Search in sources :

Example 11 with TopicPublisher

use of javax.jms.TopicPublisher in project activemq-artemis by apache.

the class ActiveMQRASession method createPublisher.

/**
 * Create a topic publisher
 *
 * @param topic The topic
 * @return The publisher
 * @throws JMSException Thrown if an error occurs
 */
@Override
public TopicPublisher createPublisher(final Topic topic) throws JMSException {
    lock();
    try {
        TopicSession session = getTopicSessionInternal();
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("createPublisher " + session + " topic=" + topic);
        }
        TopicPublisher result = session.createPublisher(topic);
        result = new ActiveMQRATopicPublisher(result, this);
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("createdPublisher " + session + " publisher=" + result);
        }
        addProducer(result);
        return result;
    } finally {
        unlock();
    }
}
Also used : TopicSession(javax.jms.TopicSession) XATopicSession(javax.jms.XATopicSession) TopicPublisher(javax.jms.TopicPublisher)

Example 12 with TopicPublisher

use of javax.jms.TopicPublisher in project activemq-artemis by apache.

the class JMSTopicConsumerTest method testSendAndReceiveOnTopic.

@Test(timeout = 60000)
public void testSendAndReceiveOnTopic() throws Exception {
    Connection connection = createConnection("myClientId");
    try {
        TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(getTopicName());
        TopicSubscriber consumer = session.createSubscriber(topic);
        TopicPublisher producer = session.createPublisher(topic);
        TextMessage message = session.createTextMessage("test-message");
        producer.send(message);
        producer.close();
        connection.start();
        message = (TextMessage) consumer.receive(1000);
        assertNotNull(message);
        assertNotNull(message.getText());
        assertEquals("test-message", message.getText());
    } finally {
        connection.close();
    }
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) TopicPublisher(javax.jms.TopicPublisher) Connection(javax.jms.Connection) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 13 with TopicPublisher

use of javax.jms.TopicPublisher in project activemq-artemis by apache.

the class JMSTopicConsumerTest method testSendAndReceiveOnAutoCreatedTopic.

@Test(timeout = 60000)
public void testSendAndReceiveOnAutoCreatedTopic() throws Exception {
    Connection connection = createConnection("myClientId");
    String topicName = UUID.randomUUID().toString();
    SimpleString simpleTopicName = SimpleString.toSimpleString(topicName);
    try {
        TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(topicName);
        TopicPublisher producer = session.createPublisher(topic);
        TextMessage message = session.createTextMessage("test-message");
        // this will auto-create the address, but not the subscription queue
        producer.send(message);
        assertNotNull(server.getAddressInfo(simpleTopicName));
        assertEquals(RoutingType.MULTICAST, server.getAddressInfo(simpleTopicName).getRoutingType());
        assertTrue(server.getAddressInfo(simpleTopicName).isAutoCreated());
        assertTrue(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
        // this will auto-create the subscription queue
        TopicSubscriber consumer = session.createSubscriber(topic);
        assertFalse(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
        producer.send(message);
        producer.close();
        connection.start();
        message = (TextMessage) consumer.receive(1000);
        assertNotNull(message);
        assertNotNull(message.getText());
        assertEquals("test-message", message.getText());
        consumer.close();
        assertTrue(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
    } finally {
        connection.close();
    }
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) TopicPublisher(javax.jms.TopicPublisher) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 14 with TopicPublisher

use of javax.jms.TopicPublisher in project brave by openzipkin.

the class TracingMessageProducer method publish.

@Override
public void publish(Topic topic, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
    checkTopicPublisher();
    TopicPublisher tp = (TopicPublisher) delegate;
    Span span = createAndStartProducerSpan(message, destination(message));
    SpanInScope ws = tracer.withSpanInScope(span);
    Throwable error = null;
    try {
        tp.publish(topic, message, deliveryMode, priority, timeToLive);
    } catch (Throwable t) {
        propagateIfFatal(t);
        error = t;
        throw t;
    } finally {
        if (error != null)
            span.error(error);
        span.finish();
        ws.close();
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) TopicPublisher(javax.jms.TopicPublisher) Span(brave.Span)

Example 15 with TopicPublisher

use of javax.jms.TopicPublisher in project brave by openzipkin.

the class TracingMessageProducer method publish.

@Override
public void publish(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
    checkTopicPublisher();
    TopicPublisher tp = (TopicPublisher) delegate;
    Span span = createAndStartProducerSpan(message, destination(message));
    SpanInScope ws = tracer.withSpanInScope(span);
    Throwable error = null;
    try {
        tp.publish(message, deliveryMode, priority, timeToLive);
    } catch (Throwable t) {
        propagateIfFatal(t);
        error = t;
        throw t;
    } finally {
        if (error != null)
            span.error(error);
        span.finish();
        ws.close();
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) TopicPublisher(javax.jms.TopicPublisher) Span(brave.Span)

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