Added Custom Message Processor for Hub & Things services.#35
Added Custom Message Processor for Hub & Things services.#35yasen-aleksandrov wants to merge 3 commits intobosch-io:devfrom
Conversation
dguggemos
left a comment
There was a problem hiding this comment.
thank you very much for your contribution! I reviewed the pull request and have some general remarks/questions, apart from the comments made to the code directly:
- the Hub changed its endpoint format, the
controlendpoints are now deprecated (I know, at the time of your pull request, they were not, sorry for the late review 😇) and will be removed soon. Could you adopt the processor to the new endpoint format? (see https://www.eclipse.org/hono/docs/api/command-and-control/) - I do not yet understand why we need two amqp clients (hub and internal). FMPOV this makes the architecture more complex than necessary. Both directions (upstream and downstream) could be achieved with one ProtonServer and one ProtonClient. Maybe I missed something?
- the MessageProcessingService does the processing only in one direction? But we have upstream and downstream messages? Maybe we need two methods?
- is it necessary that the processor always opens the connection to the Hub on its own and not only on command, when there is a connection from Things
- we discussed if it is possible to also forward authentication to avoid specifying the credentials for the Hub connection. Did you try this or was this out of scope?
Regards, Dominik
message-processor/pom.xml
Outdated
| <dependency> | ||
| <groupId>io.vertx</groupId> | ||
| <artifactId>vertx-proton</artifactId> | ||
| <version>3.8.2</version> |
There was a problem hiding this comment.
use properties for the other versions as well?
| public class Constants { | ||
| public static final String TELEMETRY_ENDPOINT = "telemetry/"; | ||
| public static final String EVENT_ENDPOINT = "event/"; | ||
| public static final String CONTROL_ENDPOINT = "control/"; |
There was a problem hiding this comment.
control endpoint is deprecated, replace with command/command_response
There was a problem hiding this comment.
Yes, I did notice some changes must have been made recently, as some things didn't work accordingly!
Will have a look at the new endpoints and make the necessary adjustments!
thanks
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| public class MessageProcessingService { |
There was a problem hiding this comment.
It makes sense to define an interface for this service, as this will be a custom implementation, depending on the use case. Furthermore we need two methods for both directions (upstream/downstream) to e.g. decrypt/encrypt, right?
There was a problem hiding this comment.
Sure, that could be done!
At the time I was just aiming to introduce the message processing in as simple as possible manner and later figure out the details.
| }); | ||
| } | ||
|
|
||
| public boolean isConnected(int timeout) { |
There was a problem hiding this comment.
I'm not sure if we should always start a connection, or only when a connection is requested.
There was a problem hiding this comment.
Well, this one is essentially going be to replacing the "out of the box" connection being defined on initial provisioning of the Asset Communication Package. Thus, I thought this connection would need to be set up and ready to handle traffic at all times?
| @Value(value = "${hub.client.host}") | ||
| private String hubHost; | ||
|
|
||
| @Value(value = "${hub.client.port}") | ||
| private Integer hubPort; | ||
|
|
||
| @Value(value = "${hub.client.username}") | ||
| private String hubUsername; | ||
|
|
||
| @Value(value = "${hub.client.password}") | ||
| private String hubPassword; |
There was a problem hiding this comment.
Is it possible to "forward" the credentials? Then we would not have to configure it for every instance.
There was a problem hiding this comment.
I will have a look and see what I could do about it!
| } | ||
|
|
||
| private void sendMessage(Message msg, String address) { | ||
| if (address.startsWith(CONTROL_ENDPOINT) && !address.endsWith(CONTROL_REPLY_ENDPOINT)) { |
There was a problem hiding this comment.
This would not be necessary if we wire the associated receivers/senders on creation (e.g. a receiver on Things side will never receive a telemetry or event message and a receiver on hub side will never receive a command message).
|
@dguggemos |
|
No, a client can only be connected to one server at a time. But the basic idea is
So there is no need to have multiple clients. The other direction works the same, but with a receiver at the server and a sender at the client. |
Address some more issues mentioned in PR comments.
|
I get your point! |
Initialize Hub connection upon Things connecting to internal amqp server.
|
@dguggemos
|
Please, refer to https://wiki.bosch-si.com/display/GTM/Custom+Message+Processor+in+Detail !