EzyMosquitto Configuration

Updated at 1689998571000

1. Configuration List

EzyMosquitto provides a list of configurations in bellow table:

PropertyDefault ValueDescription
1mosquitto.uritcp://127.0.0.1:1883MQTT 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
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)
);