Search in sources :

Example 11 with Topic

use of javax.jms.Topic in project ats-framework by Axway.

the class JmsClient method startListeningToTopic.

/**
     * Start listening for messages on topic
     * 
     * @param topicName the topic name
     */
@PublicAtsApi
public void startListeningToTopic(final String topicName) {
    final TopicInfo topicInfo = getTopicInfo(topicName);
    if (topicInfo.isListening()) {
        throw new JmsMessageException("We are already listening for messages on topic " + topicName);
    }
    try {
        final Session session = loadSession(false, Session.AUTO_ACKNOWLEDGE);
        final Topic topic = session.createTopic(topicName);
        topicInfo.topicConsumer = session.createConsumer(topic);
        topicInfo.topicConsumer.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(Message message) {
                topicInfo.addMessage(message);
            }
        });
    } catch (JMSException e) {
        throw new JmsMessageException("Could not start listening for messages on topic " + topicName, e);
    }
}
Also used : JmsMessageException(com.axway.ats.action.exceptions.JmsMessageException) Message(javax.jms.Message) BytesMessage(javax.jms.BytesMessage) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) Topic(javax.jms.Topic) Session(javax.jms.Session) ManagedSession(com.axway.ats.action.jms.model.sessions.ManagedSession) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 12 with Topic

use of javax.jms.Topic in project karaf by apache.

the class ActiveMQDestinationSourceFactory method getNames.

private List<String> getNames(Object destSource, DestinationSource.DestinationType type) {
    try {
        if (type == DestinationSource.DestinationType.Queue) {
            @SuppressWarnings("unchecked") Set<Queue> queues = (Set) destSource.getClass().getMethod("getQueues").invoke(destSource);
            List<String> names = new ArrayList<>();
            for (Queue queue : queues) {
                names.add(queue.getQueueName());
            }
            return names;
        }
        if (type == DestinationSource.DestinationType.Topic) {
            @SuppressWarnings("unchecked") Set<Topic> topics = (Set) destSource.getClass().getMethod("getTopics").invoke(destSource);
            List<String> names = new ArrayList<>();
            for (Topic topic : topics) {
                names.add(topic.getTopicName());
            }
            return names;
        }
    } catch (Exception e) {
    // Ignore
    }
    return Collections.emptyList();
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) Topic(javax.jms.Topic) Queue(javax.jms.Queue) JMSException(javax.jms.JMSException)

Example 13 with Topic

use of javax.jms.Topic in project wildfly by wildfly.

the class JMSTopicAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(context.getCurrentAddress());
    final ServiceTarget serviceTarget = context.getServiceTarget();
    // Do not pass the JNDI bindings to ActiveMQ but install them directly instead so that the
    // dependencies from the BinderServices to the JMSQueueService are not broken
    JMSTopicService jmsTopicService = JMSTopicService.installService(name, serviceName, serviceTarget, new String[0]);
    final ServiceName jmsTopicServiceName = JMSServices.getJmsTopicBaseServiceName(serviceName).append(name);
    for (String entry : CommonAttributes.DESTINATION_ENTRIES.unwrap(context, model)) {
        BinderServiceUtil.installBinderService(serviceTarget, entry, jmsTopicService, jmsTopicServiceName);
    }
    List<String> legacyEntries = CommonAttributes.LEGACY_ENTRIES.unwrap(context, model);
    if (!legacyEntries.isEmpty()) {
        Topic legacyTopic = HornetQJMSClient.createTopic(name);
        for (String legacyEntry : legacyEntries) {
            BinderServiceUtil.installBinderService(serviceTarget, legacyEntry, legacyTopic);
        }
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) Topic(javax.jms.Topic)

Example 14 with Topic

use of javax.jms.Topic in project wildfly by wildfly.

the class DeployedXmlJMSTestCase method testDeployedTopic.

@Test
public void testDeployedTopic() throws Throwable {
    final Topic topic = (Topic) initialContext.lookup("java:/topic1");
    Assert.assertNotNull(topic);
}
Also used : Topic(javax.jms.Topic) Test(org.junit.Test)

Example 15 with Topic

use of javax.jms.Topic in project tomee by apache.

the class LocalClientTest method testJmsConnection.

private void testJmsConnection(final javax.jms.Connection connection) throws JMSException {
    final Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    final Topic topic = session.createTopic("test");
    final MessageProducer producer = session.createProducer(topic);
    producer.send(session.createMessage());
    producer.close();
    session.close();
    connection.close();
}
Also used : MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) Session(javax.jms.Session)

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