moquette-io / moquette

Java MQTT lightweight broker
http://moquette-io.github.io/moquette/
Apache License 2.0
2.31k stars 818 forks source link

Using Moquette for Request/Response #378

Closed ghost closed 6 years ago

ghost commented 6 years ago

I have embedded the Moquette into a SpringBoot application and I need to use it as I would use the Stomp broker

Each client will create its own topics for request, response and event based on its /request/{client_id}, /response/{client_id} and /event/{client_id}

Is it feasible and if its feasible is it a bad idea? Basically replying to a message is clear with internalPublish but is there a way to internally subscribe?

0.10

java version "9.0.1"

Linux 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

ghost commented 6 years ago

Ok I guess I will have to do it with io.moquette.interception.InterceptHandler onPublish method but please let me know what do you think. moquette is one of the best projects I have ever seen concerning quality and performance. If it is not bad idea to mimic Request/Response then why not.

windbender commented 6 years ago

There is no reason you cannot embed moquette and to setup topics for "request" and "response". You WILL want to carefully consider the authorization and authentication functionality on the broker.

I would NOT go down the pathway of using the onPublish method in the interceptHandler. Rather, use something like Paho's Java MQTT client and subscribe/publish on those topics. This is a far better separation of concerns for your application and allows you to de-embed the broker someday if you choose to do so.

One thing to think about in your application design is to do the minimum processing necessary in the messageArrived method(assuming you use Paho's API here ). For example pushing messages onto a queue or a ThreadPoolExecutor. If your "reply" with a response is quick, then perhaps it's as simple as publishing a response.

ghost commented 6 years ago

Thank you for your answer. I really appreciate this.

I would NOT go down the pathway of using the onPublish method in the interceptHandler. Rather, use something like Paho's Java MQTT client and subscribe/publish on those topics. This is a far better separation of concerns for your application and allows you to de-embed the broker someday if you choose to do so.

I do not want to be connected on the topic through the Spring Boot app using a socket connection; since moquette is embedded in the app. I need a way to have the messages published by the client to be handed to a Spring Controller just like the Stomp example I provided. I know it is easy to connect to an MQTT topic with Spring.