use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class IndividualAcknowledgeQueueMessageIT method messageTestBase.
private void messageTestBase(MessageTestType mtt) throws Exception {
int noToSend = 10;
int noToAck = 5;
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);
for (int i = 0; i < noToSend; ++i) {
queueSender.send(mtt.gen(queueSession, (Serializable) queue));
}
} finally {
reconnect();
}
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, RMQSession.CLIENT_INDIVIDUAL_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
int i = 0;
for (; i < noToSend - noToAck; ++i) {
Message msg = queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
mtt.check(msg, (Serializable) queue);
}
for (; i < noToSend; ++i) {
Message msg = queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
mtt.check(msg, (Serializable) queue);
msg.acknowledge();
}
} finally // requeues unacknowledged messages
{
reconnect();
}
{
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
for (int i = noToSend - noToAck; i < noToSend; ++i) {
Message msg = queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
mtt.check(msg, (Serializable) queue);
}
}
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class AsyncConsumerIT method testSendAndAsyncReceiveTextMessage.
/**
* Basic send and receive with a Consumer. Uses serial send followed by async receive.
* @throws Exception if test error.
*/
@Test
public void testSendAndAsyncReceiveTextMessage() throws Exception {
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = queueSession.createTextMessage(MESSAGE);
queueSender.send(message);
} finally {
reconnect();
}
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
CountDownLatch latch = new CountDownLatch(1);
MessageListener listener = new MessageListener(latch);
queueReceiver.setMessageListener(listener);
latch.await(1000, TimeUnit.MILLISECONDS);
TextMessage message = (TextMessage) listener.getLastMessage();
assertEquals(MESSAGE, message.getText());
assertEquals(1, listener.getMessageCount());
assertTrue(listener.isSuccess());
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class LimitedBrowseQueueMessageIT method messageTestBase.
private void messageTestBase(MessageTestType mtt, String selector, int numSend, 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);
for (int i = 0; i < numSend; ++i) 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);
for (int i = 0; i < numSend; ++i) mtt.check(queueReceiver.receive(TEST_RECEIVE_TIMEOUT), (Serializable) queue);
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class AmqpPropertiesCustomiserIT method customiserIsApplied.
@Test
public void customiserIsApplied() throws Exception {
channel.queueDeclare(QUEUE_NAME, // durable
false, // exclusive
true, // autoDelete
true, // options
null);
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
// write-only AMQP-mapped queue
Queue queue = new RMQDestination(QUEUE_NAME, "", QUEUE_NAME, null);
QueueSender queueSender = queueSession.createSender(queue);
TextMessage message = queueSession.createTextMessage(MESSAGE);
queueSender.send(message);
queueConn.close();
GetResponse response = channel.basicGet(QUEUE_NAME, false);
assertNotNull(response, "basicGet failed to retrieve a response");
byte[] body = response.getBody();
assertNotNull(body, "body of response is null");
assertEquals(new String(body), MESSAGE, "body of response is not correct");
assertEquals(response.getProps().getContentType(), TEXT_PLAIN, "body of response is not correct");
}
Aggregations