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);
}
}
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();
}
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);
}
}
}
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);
}
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();
}
Aggregations