use of javax.jms.Session in project ats-framework by Axway.
the class JmsClient method sendTextMessage.
private void sendTextMessage(final Connection connection, final Destination destination, final String textMessage, final Map<String, ?> properties) {
try {
final Session session = loadSession(false, Session.AUTO_ACKNOWLEDGE);
doSendTextMessage(session, destination, textMessage, properties);
} catch (Exception e) {
throw new JmsMessageException("Failed to send message", e);
}
}
use of javax.jms.Session in project ats-framework by Axway.
the class JmsClient method createTopic.
/**
* Create a topic
*
* @param topicName the topic name
*/
@PublicAtsApi
public void createTopic(final String topicName) {
try {
final Session session = loadSession(false, Session.AUTO_ACKNOWLEDGE);
final Topic topic = session.createTopic(topicName);
session.createConsumer(topic).close();
} catch (JMSException e) {
throw new JmsMessageException("Could not start listening for messages on topic " + topicName, e);
} finally {
releaseSession(false);
}
}
use of javax.jms.Session 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.Session in project adempiere by adempiere.
the class TopicExportProcessor method sendJMSMessage.
private void sendJMSMessage(String host, int port, String msg, String protocol, String topicName, String clientID, String userName, String password, int timeToLive, boolean isDeliveryModePersistent) throws JMSException {
// Create a ConnectionFactory
// network protocol (tcp, ...) set as EXP_ProcessorParameter
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(protocol + "://" + host + ":" + port);
Connection connection = null;
Session session = null;
try {
// Create a Connection
if (userName != null && password != null) {
connection = connectionFactory.createConnection(userName, password);
} else {
connection = connectionFactory.createConnection();
}
// connection.setClientID( clientID ); Commented by Victor as he had issue!
connection.start();
// Create a Session
//TODO - Trifon could be EXP_ProcessorParameter
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createTopic(topicName);
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
// EXP_ProcessorParameter
producer.setTimeToLive(timeToLive);
if (isDeliveryModePersistent) {
// EXP_ProcessorParameter
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
} else {
// EXP_ProcessorParameter
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
// How to send to multiple destinations.
//MessageProducer producer = session.createProducer(null);
//producer.send(someDestination, message);
//producer.send(anotherDestination, message);
// Create a message
TextMessage message = session.createTextMessage(msg);
// Tell the producer to send the message
try {
producer.send(message);
session.commit();
log.info("JMS Message sent!");
} catch (JMSException ex) {
session.rollback();
log.info("JMS Can't send the message!");
throw ex;
}
} finally {
// Clean up
if (session != null) {
try {
session.close();
} catch (JMSException ex) {
/* ignored */
}
}
if (connection != null) {
try {
connection.close();
} catch (JMSException ex) {
/* ignored */
}
}
}
}
use of javax.jms.Session in project beam by apache.
the class JmsIOTest method testWriteMessage.
@Test
public void testWriteMessage() throws Exception {
ArrayList<String> data = new ArrayList<>();
for (int i = 0; i < 100; i++) {
data.add("Message " + i);
}
pipeline.apply(Create.of(data)).apply(JmsIO.write().withConnectionFactory(connectionFactory).withQueue(QUEUE).withUsername(USERNAME).withPassword(PASSWORD));
pipeline.run();
Connection connection = connectionFactory.createConnection(USERNAME, PASSWORD);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE));
int count = 0;
while (consumer.receive(1000) != null) {
count++;
}
assertEquals(100, count);
}
Aggregations