List of usage examples for javax.jms TopicConnection setClientID
void setClientID(String clientID) throws JMSException;
From source file:org.apache.activemq.usecases.DurableSubscriptionHangTestCase.java
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();//from w w w. ja v a 2 s .c o m durableSubscriber.close(); connection.close(); LOG.info("Durable Sub Registered"); }
From source file:org.apache.activemq.usecases.DurableSubscriptionHangTestCase.java
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();// w ww . j av a 2s .co m 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; }
From source file:org.openhie.openempi.notification.impl.NotificationServiceImpl.java
public void registerListener(String eventTypeName, MessageHandler handler) { if (brokerService == null || !brokerInitialized) { log.debug("The broker service is not running in registerListener."); return;//from ww w .j av a 2 s. c om } log.info("Registering handler for event " + eventTypeName); if (!isValidHandler(handler)) { return; } Topic topic = topicMap.get(eventTypeName); if (topic == null) { log.error("Caller attempted to register interest to events of unknown type " + eventTypeName); throw new RuntimeException("Unknown event type specified in registration request."); } if (isListenerRegistered(handler, eventTypeName)) { log.warn("Caller attempted to register interest for the same event again."); return; } ConnectionFactory connectionFactory = jmsTemplate.getConnectionFactory(); try { TopicConnection connection = (TopicConnection) connectionFactory.createConnection(); if (connection.getClientID() == null) { connection.setClientID(handler.getClientId()); } log.debug("Connection is of type " + connection); TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicSubscriber subscriber = topicSession.createSubscriber(topic); MessageListenerImpl listener = new MessageListenerImpl(connection, topicSession, subscriber, handler); saveListenerRegistration(listener, eventTypeName); subscriber.setMessageListener(listener); connection.start(); } catch (JMSException e) { log.error("Failed while setting up a registrant for notification events. Error: " + e, e); throw new RuntimeException("Unable to setup registration for event notification: " + e.getMessage()); } }