[
https://issues.apache.org/jira/browse/ARTEMIS-322?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15317107#comment-15317107
]
ASF subversion and git services commented on ARTEMIS-322:
---------------------------------------------------------
Commit e53649a6b9052b4b3a8387274b59c1e5585c9500 in activemq-artemis's branch
refs/heads/master from [~jbertram]
[ https://git-wip-us.apache.org/repos/asf?p=activemq-artemis.git;h=e53649a ]
ARTEMIS-322 auto-create/delete JMS topic
Implements a new feature for the broker whereby it may automatically create and
delete JMS topics which are not explicitly defined through the management API
or file-based configuration. A JMS topic is created in response to a sent
message or connected subscriber. The topic may subsequently be deleted when it
no longer has any subscribers. Auto-creation and auto-deletion can both be
turned on/off via address-setting.
> Implement Topic Auto-create
> ---------------------------
>
> Key: ARTEMIS-322
> URL: https://issues.apache.org/jira/browse/ARTEMIS-322
> Project: ActiveMQ Artemis
> Issue Type: New Feature
> Components: Broker
> Affects Versions: 1.1.0
> Environment: CentOS, Java 1.7, Eclipse, Artemis 1.1.0
> Reporter: Roan
> Assignee: Justin Bertram
> Labels: newbie
>
> I was running a Topic example, as listed bellow.
> {code:title=TestCase.java|borderStyle=solid}
> @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();
> }
> {code}
> Where my publisher and subscriber are:
> {code:title=Publisher.java|borderStyle=solid}
> 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);
> }
> }
> {code}
> {code:title=Subscriber.java|borderStyle=solid}
> 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;
> }
> }
> {code}
> 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.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)