Search in sources :

Example 6 with TopicPublisher

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();
}
Also used : TopicPublisher(javax.jms.TopicPublisher)

Example 7 with TopicPublisher

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);
}
Also used : TopicPublisher(javax.jms.TopicPublisher) Topic(javax.jms.Topic)

Example 8 with TopicPublisher

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);
    }
}
Also used : Type(org.candlepin.audit.Event.Type) TopicPublisher(javax.jms.TopicPublisher) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException)

Example 9 with TopicPublisher

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);
    }
}
Also used : Target(org.candlepin.audit.Event.Target) Type(org.candlepin.audit.Event.Type) HashMap(java.util.HashMap) TopicPublisher(javax.jms.TopicPublisher)

Example 10 with TopicPublisher

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;
}
Also used : TopicPublisher(javax.jms.TopicPublisher) Topic(javax.jms.Topic)

Aggregations

TopicPublisher (javax.jms.TopicPublisher)38 TopicSession (javax.jms.TopicSession)27 TextMessage (javax.jms.TextMessage)23 Topic (javax.jms.Topic)23 TopicSubscriber (javax.jms.TopicSubscriber)22 Test (org.junit.Test)15 TopicConnection (javax.jms.TopicConnection)14 Message (javax.jms.Message)11 Test (org.junit.jupiter.api.Test)8 JMSException (javax.jms.JMSException)4 Span (brave.Span)3 SpanInScope (brave.Tracer.SpanInScope)3 RMQTextMessage (com.rabbitmq.jms.client.message.RMQTextMessage)3 Connection (javax.jms.Connection)3 BytesMessage (javax.jms.BytesMessage)2 MapMessage (javax.jms.MapMessage)2 ObjectMessage (javax.jms.ObjectMessage)2 NamingException (javax.naming.NamingException)2 Type (org.candlepin.audit.Event.Type)2 ACSJMSTextMessage (com.cosylab.acs.jms.ACSJMSTextMessage)1