use of javax.jms.Topic in project hive by apache.
the class NotificationListener method isConnectionHealthy.
/**
* Send a dummy message to probe if the JMS connection is healthy
* @return true if connection is healthy, false otherwise
*/
protected boolean isConnectionHealthy() {
try {
Topic topic = createTopic(getTopicPrefix(getConf()) + "." + HEALTH_CHECK_TOPIC_SUFFIX);
MessageProducer producer = createProducer(topic);
Message msg = session.get().createTextMessage(HEALTH_CHECK_MSG);
producer.send(msg, DeliveryMode.NON_PERSISTENT, 4, 0);
} catch (Exception e) {
return false;
}
return true;
}
use of javax.jms.Topic in project spring-framework by spring-projects.
the class DynamicDestinationResolverTests method resolveWithPubSubTopicSession.
@Test
public void resolveWithPubSubTopicSession() throws Exception {
Topic expectedDestination = new StubTopic();
TopicSession session = mock(TopicSession.class);
given(session.createTopic(DESTINATION_NAME)).willReturn(expectedDestination);
testResolveDestination(session, expectedDestination, true);
}
use of javax.jms.Topic in project ACS by ACS-Community.
the class PubSubTest method testTopicConnection.
public void testTopicConnection() throws Exception {
TopicConnection topicConnection = factory.createTopicConnection();
assertNotNull("Error creating the TopicConnection", topicConnection);
TopicSession topicSession = topicConnection.createTopicSession(true, 0);
assertNotNull("Error creating the TopicSession", topicSession);
String chName = "TOPIC.TEST";
Topic topic = topicSession.createTopic(chName);
assertNotNull("Error creating Topic", topic);
assertEquals("Wrong name for the topic", chName, topic.getTopicName());
TopicPublisher publisher = topicSession.createPublisher(topic);
assertNotNull("Error creating the TopicPublisher ", publisher);
TopicSubscriber subscriber = topicSession.createSubscriber(topic);
assertNotNull("Error creating the TopicSubscriber", subscriber);
subscriber.setMessageListener(this);
ACSJMSTextMessage msg = new ACSJMSTextMessage(getContainerServices());
assertNotNull("Error creating ACSJMSTextMessage", msg);
msg.setText(msgToSend);
publisher.publish(msg);
// Wait for awhile to have enough time to receive the message
try {
Thread.sleep(10000);
} catch (Exception e) {
}
publisher.close();
subscriber.close();
}
use of javax.jms.Topic in project ACS by ACS-Community.
the class DefaultSubscriberImpl method subscribe.
/**
* Method subscribe
*
*
* @param topic
* @param listener
* @param selector
*
* @return long the subscription handle identifier
*
* @throws JMSException
* @throws NamingException
*
*/
public long subscribe(String topic, SubscriptionListener listener, String selector) throws JMSException, NamingException {
cat.info("subscribe(" + topic + ", listener, " + selector + ")");
if (closed) {
throw (new JMSException("Subscriber closed."));
}
SubscriptionHandle handle = new SubscriptionHandle();
handle.setSubscriptionTopic(topic);
handle.setSubscriptionSelector(selector);
handle.setSubscriptionListener(listener);
StringBuffer local_selector = new StringBuffer();
if (NotificationHelper.isNotification(topic)) {
// this is a subscription to notifications, no further selection is required
local_selector.append(selector);
} else {
// subscription to a generic topic, adding subscriber specific selection
if (selector != null) {
local_selector.append(selector);
local_selector.append(" AND ");
}
local_selector.append("( (");
local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
local_selector.append(" IS NULL) OR (");
local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
local_selector.append(" = '");
local_selector.append(subscriberId);
local_selector.append("@");
local_selector.append(handle.getSubscriptionToken());
local_selector.append("') )");
}
TopicSession session = null;
TopicSubscriber subscriber = null;
Topic the_topic = createTopic(topic);
try {
session = connection.createTopicSession();
subscriber = session.createSubscriber(the_topic, local_selector.toString(), false);
} catch (JMSSecurityException jse) {
cat.error("JMSSecurityException caught");
throw (new NamingException(jse.getMessage()));
} catch (JMSException je) {
cat.error("JMSException caught");
throw (new NamingException(je.getMessage()));
} catch (ConnectionException ce) {
cat.error("ConnectionException caught");
throw (new JMSException(ce.getMessage()));
} catch (Exception e) {
cat.error("Generic exception caught", e);
}
subscriber.setMessageListener(listener);
handle.setSubscriber(subscriber);
handle.setSession(session);
synchronized (subscribers) {
subscribers.put(new Long(handle.getSubscriptionToken()), handle);
}
if (!NotificationHelper.isNotification(topic)) {
publishNotification(NotificationHelper.CONSUMER_OPEN_NOTIFICATION, handle);
}
return handle.getSubscriptionToken();
}
use of javax.jms.Topic in project ACS by ACS-Community.
the class DefaultSubscriberImpl method publishNotification.
/**
* Method publishNotification
*
* @param type
* @param handle
* @throws JMSException
*/
private void publishNotification(int type, SubscriptionHandle handle) throws JMSException {
if (notificationsEnabled) {
cat.info("publishNotification(" + type + ", " + handle.getSubscriptionTopic() + ", " + handle.getSubscriptionSelector() + ")");
notificationMessage.setIntProperty(NotificationHelper.NOTIFICATION_TYPE_PROPERTY, type);
notificationMessage.setStringProperty(NotificationHelper.SELECTOR_PROPERTY, handle.getSubscriptionSelector());
notificationMessage.setStringProperty(NotificationHelper.TOPIC_PROPERTY, handle.getSubscriptionTopic());
notificationMessage.setStringProperty(NotificationHelper.SUBSCRIPTION_ID_PROPERTY, subscriberId + "@" + handle.getSubscriptionToken());
Topic t = null;
try {
t = createTopic(NotificationHelper.CarrierTopics[type]);
} catch (NamingException ne) {
ne.printStackTrace();
}
notificationPublisher.publish(t, notificationMessage);
}
}
Aggregations