Java Code Examples for javax.jms.TopicConnection#setClientID()

The following examples show how to use javax.jms.TopicConnection#setClientID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DurableSubscriptionHangTestCase.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private Message collectMessagesFromDurableSubscriptionForOneMinute() throws Exception {
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName);
   TopicConnection connection = connectionFactory.createTopicConnection();

   connection.setClientID(clientID);
   TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
   Topic topic = topicSession.createTopic(topicName);
   connection.start();
   TopicSubscriber subscriber = topicSession.createDurableSubscriber(topic, durableSubName);
   LOG.info("About to receive messages");
   Message message = subscriber.receive(120000);
   subscriber.close();
   connection.close();
   LOG.info("collectMessagesFromDurableSubscriptionForOneMinute done");

   return message;
}
 
Example 2
Source File: DurableSubscriptionHangTestCase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void registerDurableSubscription() throws JMSException {
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName);
   TopicConnection connection = connectionFactory.createTopicConnection();
   connection.setClientID(clientID);
   TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
   Topic topic = topicSession.createTopic(topicName);
   TopicSubscriber durableSubscriber = topicSession.createDurableSubscriber(topic, durableSubName);
   connection.start();
   durableSubscriber.close();
   connection.close();
   LOG.info("Durable Sub Registered");
}
 
Example 3
Source File: NonDurableSubscriberTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test introduced as a result of a TCK failure.
 */
@Test
public void testNonDurableSubscriberInvalidUnsubscribe() throws Exception {
   TopicConnection conn = createTopicConnection();
   conn.setClientID("clientIDxyz123");

   TopicSession ts = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

   try {
      ts.unsubscribe("invalid-subscription-name");
      ProxyAssertSupport.fail("this should fail");
   } catch (javax.jms.InvalidDestinationException e) {
      // OK
   }
}
 
Example 4
Source File: NonDurableSubscriberTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidSelectorOnSubscription() throws Exception {
   TopicConnection c = createTopicConnection();
   c.setClientID("something");

   TopicSession s = c.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

   try {
      s.createSubscriber(ActiveMQServerTestCase.topic1, "=TEST 'test'", false);
      ProxyAssertSupport.fail("this should fail");
   } catch (InvalidSelectorException e) {
      // OK
   }
}
 
Example 5
Source File: AndesJMSConsumer.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a topic connection, session and receiver.
 *
 * @throws NamingException
 * @throws JMSException
 */
private void createTopicConnection() throws NamingException, JMSException {
    // Creates a topic connection, sessions and receiver
    TopicConnectionFactory connFactory = (TopicConnectionFactory) super.getInitialContext()
            .lookup(AndesClientConstants.CF_NAME);
    TopicConnection topicConnection = connFactory.createTopicConnection();
    topicConnection.setClientID(this.consumerConfig.getSubscriptionID());
    topicConnection.start();
    TopicSession topicSession;
    // Sets acknowledgement mode
    if (TopicSession.SESSION_TRANSACTED == this.consumerConfig.getAcknowledgeMode().getType()) {
        topicSession = topicConnection
                .createTopicSession(true, this.consumerConfig.getAcknowledgeMode().getType());
    } else {
        topicSession = topicConnection
                .createTopicSession(false, this.consumerConfig.getAcknowledgeMode().getType());
    }

    Topic topic =
            (Topic) super.getInitialContext().lookup(this.consumerConfig.getDestinationName());

    connection = topicConnection;
    session = topicSession;
    // If topic is durable
    if (this.consumerConfig.isDurable()) {
        // If selectors exists
        if (null != this.consumerConfig.getSelectors()) {
            receiver = topicSession.createDurableSubscriber(topic, this.consumerConfig
                    .getSubscriptionID(), this.consumerConfig.getSelectors(), false);
        } else {
            receiver = topicSession
                    .createDurableSubscriber(topic, this.consumerConfig.getSubscriptionID());
        }
    } else {
        // If selectors exists
        if (null != this.consumerConfig.getSelectors()) {
            receiver = topicSession
                    .createSubscriber(topic, this.consumerConfig.getSelectors(), false);
        } else {
            receiver = topicSession.createSubscriber(topic);
        }
    }
}