Details
Description
I was running a Topic example, as listed bellow.
TestCase.java
@Test public void testSendTextMessageToDestination() throws Exception { Publisher pub = new Publisher(); pub.create("5", "topic"); pub.sendName("Roan", "Monteiro"); String greeting1 = new Subscriber().getGreeting(1000); assertEquals("Hello Roan Monteiro!", greeting1); pub.closeConnection(); }
Where my publisher and subscriber are:
Publisher.java
package com.redhat.messaging.topicagents; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; import org.apache.activemq.artemis.api.core.TransportConfiguration; import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; import org.apache.activemq.artemis.api.jms.JMSFactoryType; import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Non-Durable Subscrition * @author roanbrasil * */ public class Publisher { private static final Logger LOGGER = LoggerFactory .getLogger(Publisher.class); private String clientId; private Connection connection; private Session session; private MessageProducer messageProducer; public void create(String clientId, String topicName) throws JMSException { this.clientId = clientId; // create a Connection Factory TransportConfiguration transportConfiguration = new TransportConfiguration( NettyConnectorFactory.class.getName()); ConnectionFactory cf = ActiveMQJMSClient .createConnectionFactoryWithoutHA(JMSFactoryType.TOPIC_CF, transportConfiguration); // create a Connection connection = cf.createConnection(); connection.setClientID(clientId); // create a Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // create the Topic to which messages will be sent Topic topic = session.createTopic(topicName); // create a MessageProducer for sending messages messageProducer = session.createProducer(topic); } public void closeConnection() throws JMSException { connection.close(); } public void sendName(String firstName, String lastName) throws JMSException { String text = firstName + " " + lastName; // create a JMS TextMessage TextMessage textMessage = session.createTextMessage(text); // send the message to the topic destination messageProducer.send(textMessage); LOGGER.debug(clientId + ": sent message with text='{}'", text); } }
Subscriber.java
package com.redhat.messaging.topicagents; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; import org.apache.activemq.artemis.api.core.TransportConfiguration; import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; import org.apache.activemq.artemis.api.jms.JMSFactoryType; import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Subscriber { private static final Logger LOGGER = LoggerFactory .getLogger(Subscriber.class); private static final String NO_GREETING = "no greeting"; private String clientId; private Connection connection; private Session session; private MessageConsumer messageConsumer; public void create(String clientId, String topicName) throws JMSException { this.clientId = clientId; // create a Connection Factory TransportConfiguration transportConfiguration = new TransportConfiguration( NettyConnectorFactory.class.getName()); ConnectionFactory cf = ActiveMQJMSClient .createConnectionFactoryWithoutHA(JMSFactoryType.TOPIC_CF, transportConfiguration); // create a Connection connection = cf.createConnection(); connection.setClientID(clientId); // create a Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // create the Topic from which messages will be received Topic topic = session.createTopic(topicName); // create a MessageConsumer for receiving messages messageConsumer = session.createConsumer(topic); // start the connection in order to receive messages connection.start(); } public void closeConnection() throws JMSException { connection.close(); } public String getGreeting(int timeout) throws JMSException { String greeting = NO_GREETING; // read a message from the topic destination Message message = messageConsumer.receive(timeout); // check if a message was received if (message != null) { // cast the message to the correct type TextMessage textMessage = (TextMessage) message; // retrieve the message content String text = textMessage.getText(); LOGGER.debug(clientId + ": received message with text='{}'", text); // create greeting greeting = "Hello " + text + "!"; } else { LOGGER.debug(clientId + ": no message received"); } LOGGER.info("greeting={}", greeting); return greeting; } }
When I got to ChannelImpl.class is created a temporary Topic which the name is jms.temptopic.topic. On the packet variable the type is 49 and the channel Id is 11. But the sendBlocking return the response variable with no queueNames and setting exists as false, I believe this queueName should come with topic name and the exists variable as true value.
Attachments
Issue Links
- blocks
-
ARTEMIS-412 Sending to a non existing topic using STOMP triggers an error
- Closed
- links to