RabbitMqProducer
Path
com.roma.apic.livedata.client.v1.RabbitMqProducer
Description
This class is used to produce RabbitMQ messages. If no exception occurs during message sending, messages are sent successfully. If an exception occurs during message sending, messages fail to be sent.
Example
- Use the direct switch to generate messages and route the messages to the queue in which the bindingKey and routingKey are fully matched.
importClass(com.roma.apic.livedata.client.v1.RabbitMqProducer); importClass(com.roma.apic.livedata.config.v1.RabbitMqConfig); importClass(com.roma.apic.livedata.config.v1.QueueConfig); importClass(com.roma.apic.livedata.config.v1.ExchangeConfig); importClass(com.roma.apic.livedata.config.v1.ConnectionConfig); function execute(data) { var connectionConfig = new ConnectionConfig("10.10.10.10", 5672, "admin", "123456"); var queueConfig = new QueueConfig("directQueue", false, false, false, null); var exchangeConfig = new ExchangeConfig("directExchange", "direct", true, false, false, null); var config = new RabbitMqConfig(connectionConfig, queueConfig, exchangeConfig); var producer = new RabbitMqProducer(config); producer.produceWithDirectExchange("direct.exchange", "PERSISTENT_TEXT_PLAIN", "direct exchange message"); return "produce successful."; }
- Use the topic switch to generate messages and route the messages to the queue in which the bindingKey and routingKey are matched in fuzzy mode.
importClass(com.roma.apic.livedata.client.v1.RabbitMqProducer); importClass(com.roma.apic.livedata.config.v1.RabbitMqConfig); importClass(com.roma.apic.livedata.config.v1.QueueConfig); importClass(com.roma.apic.livedata.config.v1.ExchangeConfig); importClass(com.roma.apic.livedata.config.v1.ConnectionConfig); function execute(data) { var connectionConfig = new ConnectionConfig("10.10.10.10", 5672, "admin", "123456"); var queueConfig = new QueueConfig ("topicQueue", false, false, false, null); var exchangeConfig = new ExchangeConfig("topicExchange", "topic", true, false, false, null); var config = new RabbitMqConfig(connectionConfig, queueConfig, exchangeConfig); var producer = new RabbitMqProducer(config); producer.produceWithTopicExchange("topic.#", "topic.A", null, "message"); return "produce successful."; }
- Use the fanout switch to generate messages and route all messages sent to the exchange to all the queues bound to it.
importClass(com.roma.apic.livedata.client.v1.RabbitMqProducer); importClass(com.roma.apic.livedata.config.v1.RabbitMqConfig); importClass(com.roma.apic.livedata.config.v1.QueueConfig); importClass(com.roma.apic.livedata.config.v1.ExchangeConfig); importClass(com.roma.apic.livedata.config.v1.ConnectionConfig); function execute(data) { var connectionConfig = new ConnectionConfig("10.10.10.10", 5672, "admin", "123456"); var queueConfig = new QueueConfig ("fanoutQueue", false, false, false, null); var exchangeConfig = new ExchangeConfig ("fanoutExchange", "fanout", true, false, null) var config = new RabbitMqConfig(connectionConfig, queueConfig, exchangeConfig); var producer = new RabbitMqProducer(config); producer.produceWithFanoutExchange(null, "message") return "produce successfull" }
Constructor Details
public RabbitMqProducer(RabbitMqConfig rabbitMqConfig)
Constructs a RabbitMQ message producer.
Parameter: rabbitMqConfig indicates configuration information of RabbitMQ.
Method List
Returned Type |
Method and Description |
---|---|
void |
produceWithDirectExchange(String routingKey, String props, String message) Use the direct switch to generate messages and route the messages to the queue in which the bindingKey and routingKey are fully matched. |
void |
produceWithTopicExchange(String bindingKey, String routingKey, String props, String message) Use the topic switch to generate messages and route the messages to the queue in which the bindingKey and routingKey are matched in fuzzy mode. |
void |
produceWithFanoutExchange(String props, String message) Use the fanout switch to generate messages and route all messages sent to the exchange to all the queues bound to it. |
Method Details
- public void produceWithDirectExchange(String routingKey, String props, String message)
Use the direct switch to generate messages and route the messages to the queue in which the bindingKey and routingKey are fully matched.
Input Parameters
- routingKey indicates the message routing key.
- props indicates the message persistency setting, which is optional.
- message indicates the message content.
- public void produceWithTopicExchange(String bindingKey, String routingKey, String props, String message)
Use the topic switch to generate messages and route the messages to the queue in which the bindingKey and routingKey are matched in fuzzy mode.
Input Parameters
- bindingKey indicates the queue binding key.
- routingKey indicates the message routing key.
- props indicates the message persistency setting, which is optional.
- message indicates the message content.
- produceWithFanoutExchange(String props, String message)
Use the fanout switch to generate messages and route all messages sent to the exchange to all the queues bound to it.
Input Parameters
- props indicates the message persistency setting, which is optional.
- message indicates the message content.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot