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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations