EzyMosquitto Configuration

Updated at 1689998571000

1. Configuration List

EzyMosquitto provides a list of configurations in bellow table:

PropertyDefault ValueDescription
1mosquitto.uritcp:// broker uri
2mosquitto.usernamenullMQTT broker username
3mosquitto.passwordnullMQTT broker password
3mosquitto.client_prefixnullClient id prefix
6mosquitto.producersnullList of MQTT producers
5mosquitto.consumersnullList of MQTT consumers
7mosquitto.topicsnullList of MQTT topics

For every producer, EzyMosquitto provides bellow properties:

PropertyDefault ValueDescription
1topic[producer name]-requestName of the request topic
2reply_topic[producer name]-replyName of the reply topic
4capacity10000Capacity of the producer
5default_timeoutno timeoutDefault timeout of a rpc request in millisecond

For every consumer, EzyMosquitto provides bellow properties:

PropertyDefault ValueDescription
1topic[consumer name]-requestName of the request topic
2reply_topic[consumer name]-replyName of reply topic to producer
3thread_pool_size1Thread pool size for rquest message consumer

For every topic, EzyMosquitto provides bellow properties:

PropertyDefault ValueDescription
1producernullProducer for the topic settings
2producer.enabletrue if producer is not nullEnable producer or not
3consumernullConsumer for the topic settings
4consumer.enabletrue if consumer is not nullEnable 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
    test: default
    test: default
      producer: default
      consumer: default

Or for application.properties file:

# for application.properties

3. Configure for producer

You can configure for producer like this:

EzyMosquittoProxy proxy = EzyMosquittoProxy.builder()
    .mapTopicMessageType("hello", "hello", SumRequest.class)
EzyMosquittoRpcProducer producer = proxy.getRpcProducer("test");

4. Configure for consumer

You can configure for consumer like this:


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)