use of javax.jms.TopicPublisher in project iaf by ibissource.
the class JMSFacade method sendByTopic.
protected String sendByTopic(TopicSession session, Topic destination, Message message) throws NamingException, JMSException {
TopicPublisher tps = session.createPublisher(destination);
tps.publish(message);
tps.close();
return message.getJMSMessageID();
}
use of javax.jms.TopicPublisher in project candlepin by candlepin.
the class QpidConnection method storeTopicProducer.
private void storeTopicProducer(Type type, Target target, Map<Type, TopicPublisher> map) throws JMSException, NamingException {
String name = config.getTopicName(type, target);
Topic topic = lookupTopic(name);
log.debug("Creating publisher for topic: {}", name);
TopicPublisher tp = this.session.createPublisher(topic);
map.put(type, tp);
}
use of javax.jms.TopicPublisher in project candlepin by candlepin.
the class QpidConnection method sendTextMessage.
/**
* Sends a text message to a Qpid Broker. The message will be sent with a binding key that is
* appropriate to the provided Target and Type enumerations. One example one such binding key
* is CONSUMER.CREATED. This further allows Qpid clients to filter out events that
* they are interested in. The reason that for each binding key we have separate
* TopicPublisher is an implementation detail of the Qpid java client.
* @param target enumeration
* @param type enumeration
* @param msg Usually contains serialized JSON with the message
* @throws Exception
*/
public void sendTextMessage(Target target, Type type, String msg) {
try {
/**
* When Candlepin is in NORMAL mode and at the same time the
* JMS objects are stale, it is necessary to recreate them.
*/
if (connectionStatus == STATUS.JMS_OBJECTS_STALE && modeManager.getLastCandlepinModeChange().getMode() == Mode.NORMAL) {
log.debug("Recreating the stale JMS objects");
connect();
}
Map<Type, TopicPublisher> m = this.producerMap.get(target);
if (m != null) {
TopicPublisher tp = m.get(type);
tp.send(session.createTextMessage(msg));
}
} catch (Exception ex) {
log.error("Error sending text message");
connectionStatus = STATUS.JMS_OBJECTS_STALE;
if (candlepinConfig.getBoolean(ConfigProperties.SUSPEND_MODE_ENABLED)) {
modeTransitioner.transitionAppropriately();
}
throw new RuntimeException("Error sending event to message bus", ex);
}
}
use of javax.jms.TopicPublisher in project candlepin by candlepin.
the class QpidConnection method buildAllTopicPublishers.
/**
* We create all the topic publishers in advance and reuse them for sending.
* @param pm
* @throws JMSException
* @throws NamingException
*/
private void buildAllTopicPublishers(Map<Target, Map<Type, TopicPublisher>> pm) throws JMSException, NamingException {
for (Target target : Target.values()) {
Map<Type, TopicPublisher> typeToTpMap = new HashMap<>();
for (Type type : Type.values()) {
storeTopicProducer(type, target, typeToTpMap);
}
pm.put(target, typeToTpMap);
}
}
use of javax.jms.TopicPublisher in project moleculer-java by moleculer-java.
the class JmsTransporter method createOrGetPublisher.
protected TopicPublisher createOrGetPublisher(String channel) throws Exception {
TopicPublisher publisher;
synchronized (publishers) {
publisher = publishers.get(channel);
if (publisher != null) {
return publisher;
}
Topic topic = session.createTopic(channel);
publisher = session.createPublisher(topic);
publisher.setDeliveryMode(deliveryMode);
publishers.put(channel, publisher);
}
return publisher;
}
Aggregations