EzyMosquitto Configuration
Updated at 16899985710001. Configuration List
EzyMosquitto provides a list of configurations in bellow table:Property | Default Value | Description | |
1 | mosquitto.uri | tcp://127.0.0.1:1883 | MQTT broker uri |
2 | mosquitto.username | null | MQTT broker username |
3 | mosquitto.password | null | MQTT broker password |
3 | mosquitto.client_prefix | null | Client id prefix |
6 | mosquitto.producers | null | List of MQTT producers |
5 | mosquitto.consumers | null | List of MQTT consumers |
7 | mosquitto.topics | null | List of MQTT topics |
For every producer, EzyMosquitto provides bellow properties:
Property | Default Value | Description | |
1 | topic | [producer name]-request | Name of the request topic |
2 | reply_topic | [producer name]-reply | Name of the reply topic |
4 | capacity | 10000 | Capacity of the producer |
5 | default_timeout | no timeout | Default timeout of a rpc request in millisecond |
For every consumer, EzyMosquitto provides bellow properties:
Property | Default Value | Description | |
1 | topic | [consumer name]-request | Name of the request topic |
2 | reply_topic | [consumer name]-reply | Name of reply topic to producer |
3 | thread_pool_size | 1 | Thread pool size for rquest message consumer |
For every topic, EzyMosquitto provides bellow properties:
Property | Default Value | Description | |
1 | producer | null | Producer for the topic settings |
2 | producer.enable | true if producer is not null | Enable producer or not |
3 | consumer | null | Consumer for the topic settings |
4 | consumer.enable | true if consumer is not null | Enable consumer or not |
2. An Example
Let's we neen create a producer and a consumer named test
and a topic named hello
, you can put bellow configuration to your application.yaml
file:
# for application.yaml mosquitto: producers: test: default consumers: test: default topics: hello: producer: default consumer: default
Or for application.properties
file:
# for application.properties mosquitto.producers.test=default mosquitto.consumers.test=default mosquitto.topics.hello.producer=default mosquitto.topics.hello.consumer=default
3. Configure for producer
You can configure for producer like this:
EzyMosquittoProxy proxy = EzyMosquittoProxy.builder() .scan("com.tvd12.ezymq.mosquitto.test") .mapTopicMessageType("hello", "hello", SumRequest.class) .build(); EzyMosquittoRpcProducer producer = proxy.getRpcProducer("test");
4. Configure for consumer
You can configure for consumer like this:
EzyMosquittoProxy.builder()
.addSingleton(someSingleton)
.scan("com.tvd12.ezymq.mosquitto.test")
.build();
5. Topic usage
You can get the topic like this:
EzyMosquittoTopic<SumRequest> sumTopic = proxy.getTopic("hello");
And use the topic to publish a message like this:
sumTopic.publish("hello", new SumRequest(a, b));
You also can add message consumer for the topic like this:
sumTopic.addConsumer("hello", message -> System.out.println("sum request: " + message) );