Search in sources :

Example 1 with Topic

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;
}
Also used : HCatEventMessage(org.apache.hive.hcatalog.messaging.HCatEventMessage) Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 2 with Topic

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);
}
Also used : StubTopic(org.springframework.jms.StubTopic) TopicSession(javax.jms.TopicSession) Topic(javax.jms.Topic) StubTopic(org.springframework.jms.StubTopic) Test(org.junit.Test)

Example 3 with Topic

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();
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) TopicPublisher(javax.jms.TopicPublisher) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) Topic(javax.jms.Topic) TopicConnection(javax.jms.TopicConnection)

Example 4 with Topic

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();
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) JMSSecurityException(javax.jms.JMSSecurityException) JMSException(javax.jms.JMSException) NamingException(javax.naming.NamingException) Topic(javax.jms.Topic) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) MOMException(cern.cmw.mom.pubsub.MOMException) JMSSecurityException(javax.jms.JMSSecurityException)

Example 5 with Topic

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);
    }
}
Also used : NamingException(javax.naming.NamingException) Topic(javax.jms.Topic)

Aggregations

Topic (javax.jms.Topic)59 Session (javax.jms.Session)36 MessageProducer (javax.jms.MessageProducer)31 JMSException (javax.jms.JMSException)14 NamingException (javax.naming.NamingException)14 TextMessage (javax.jms.TextMessage)9 LaserCreateException (cern.laser.business.LaserCreateException)6 LaserRuntimeException (cern.laser.business.LaserRuntimeException)6 Message (javax.jms.Message)6 Test (org.junit.Test)6 TopicSession (javax.jms.TopicSession)5 AlarmImpl (cern.laser.business.data.AlarmImpl)2 JmsMessageException (com.axway.ats.action.exceptions.JmsMessageException)2 ManagedSession (com.axway.ats.action.jms.model.sessions.ManagedSession)2 PublicAtsApi (com.axway.ats.common.PublicAtsApi)2 ACSJMSTextMessage (com.cosylab.acs.jms.ACSJMSTextMessage)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageListener (javax.jms.MessageListener)2