28 Temmuz 2020 Salı

ActiveMQ ActiveMQMessageProducer Sınıfı

send metodu - Topic + Message
Şöyle yaparız
public void publish(String topicAddress, String message) {
 String topicName = "VirtualTopic." + topicAddress;
 try {
   Connection producerConnection = factory.createConnection();
   producerConnection.start();
   Session producerSession = producerConnection.createSession(false, AUTO_ACKNOWLEDGE);
   MessageProducer producer = producerSession.createProducer(null);
   TextMessage textMessage = producerSession.createTextMessage(message);
   Topic topic = producerSession.createTopic(topicName);
   producer.send(topic, textMessage, PERSISTENT, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE);
 } catch (JMSException e) {
  throw new RuntimeException("Message could not be published", e);
 }
}

Hiç yorum yok:

Yorum Gönder