use of javax.jms.QueueSender in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method processAndReplyWithSendTo.
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, String replyDestinationName, boolean pubSubDomain) throws JMSException {
String body = "echo text";
String correlationId = "link-1234";
Destination replyDestination = new Destination() {
};
DestinationResolver destinationResolver = mock(DestinationResolver.class);
TextMessage reply = mock(TextMessage.class);
QueueSender queueSender = mock(QueueSender.class);
Session session = mock(Session.class);
given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain)).willReturn(replyDestination);
given(session.createTextMessage(body)).willReturn(reply);
given(session.createProducer(replyDestination)).willReturn(queueSender);
listener.setDestinationResolver(destinationResolver);
StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
inputMessage.setJMSCorrelationID(correlationId);
listener.onMessage(inputMessage, session);
verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
verify(reply).setJMSCorrelationID(correlationId);
verify(queueSender).send(reply);
verify(queueSender).close();
}
use of javax.jms.QueueSender in project opennms by OpenNMS.
the class DaemonContextIT method canUseEmbeddedActiveMQBroker.
/**
* Verifies that the embedded ActiveMQ broker bootstraps successfully
* and is accessible using the provided connection factory.
*/
@Test
public void canUseEmbeddedActiveMQBroker() throws Throwable {
QueueConnection connection = activeMQConnectionFactory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
TextMessage message = session.createTextMessage();
message.setText("ping");
QueueSender sender = session.createSender(session.createQueue("pong"));
sender.send(message);
}
use of javax.jms.QueueSender in project Payara by payara.
the class UnitTest method testTimer.
@Test
public void testTimer() throws Exception {
QueueConnection queueConnection = null;
QueueSession queueSession = null;
try {
InitialContext ic = new InitialContext();
QueueConnectionFactory qcf = (QueueConnectionFactory) ic.lookup("jms/TestQueueConnectionFactory");
javax.jms.Queue queue = (javax.jms.Queue) ic.lookup("jms/TestQueue");
queueConnection = qcf.createQueueConnection();
queueConnection.start();
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = queueSession.createSender(queue);
String str = "Hi From BHAVANI";
TextMessage msg = queueSession.createTextMessage(str);
sender.send(msg);
Thread.sleep(5000);
byte[] message = new byte[msg.getText().length()];
File savedFile = new File(System.getProperty("java.io.tmpdir"), "embedded_mdb_onmessage.txt");
FileInputStream is = new FileInputStream(savedFile);
is.read(message);
String savedMsg = new String(message);
if (!savedMsg.equals(str)) {
throw new Exception("Sent message [" + str + " ] does not match the received message [" + savedMsg + "]");
} else {
System.out.println("Sent message [" + str + " ] matches the received message [" + savedMsg + "]");
}
savedFile.delete();
} finally {
try {
queueSession.close();
queueConnection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class SimpleBrowseQueueMessageIT method messageTestBase.
private void messageTestBase(MessageTestType mtt, String selector, int numExpected) throws Exception {
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
drainQueue(queueSession, queue);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
queueSender.send(mtt.gen(queueSession, (Serializable) queue));
} finally {
reconnect();
}
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
{
// Browse queue before receiving message
QueueBrowser queueBrowser = queueSession.createBrowser(queue, selector);
Enumeration<?> e = queueBrowser.getEnumeration();
int numE = 0;
Message msg = null;
while (e.hasMoreElements()) {
++numE;
msg = (Message) e.nextElement();
mtt.check(msg, (Serializable) queue);
}
assertEquals(numExpected, numE, "Wrong number of messages on browse queue");
}
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
mtt.check(queueReceiver.receive(TEST_RECEIVE_TIMEOUT), (Serializable) queue);
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class SimpleQueueMessageIT method messageTestBase.
private void messageTestBase(MessageTestType mtt) throws Exception {
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
drainQueue(queueSession, queue);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
queueSender.send(mtt.gen(queueSession, (Serializable) queue));
} finally {
reconnect();
}
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
mtt.check(queueReceiver.receive(TEST_RECEIVE_TIMEOUT), (Serializable) queue);
}
Aggregations