use of javax.jms.QueueSender in project wildfly by wildfly.
the class QueueTestMDB method sendReply.
private void sendReply(Queue destination, String messageID, Exception e) throws JMSException {
QueueConnection conn = qFactory.createQueueConnection();
try {
QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(destination);
ObjectMessage message = session.createObjectMessage(e);
message.setJMSCorrelationID(messageID);
sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
} finally {
conn.close();
}
}
use of javax.jms.QueueSender in project wildfly by wildfly.
the class HelloMDB method sendReply.
private void sendReply(String msg, Queue destination, String messageID) throws JMSException {
QueueConnection conn = qFactory.createQueueConnection("guest", "guest");
try {
QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
conn.start();
QueueSender sender = session.createSender(destination);
TextMessage message = session.createTextMessage(msg);
message.setJMSCorrelationID(messageID);
sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
} finally {
conn.close();
}
}
use of javax.jms.QueueSender in project Payara by payara.
the class MessageBean method onMessage.
public void onMessage(Message message) {
System.out.println("Got message!!!");
QueueConnection connection = null;
try {
System.out.println("Calling hello1 stateless bean");
hello1.hello("local ejb3.0 stateless");
System.out.println("Calling hello2 stateful bean");
hello2.hello("local ejb3.0 stateful");
hello2.removeMethod();
try {
hello2.hello("this call should not go through");
throw new Exception("bean should have been removed " + "after removeMethod()");
} catch (NoSuchEJBException e) {
System.out.println("Successfully caught EJBException after " + " accessing removed SFSB");
}
connection = qcFactory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(clientQueue);
TextMessage tmessage = session.createTextMessage();
tmessage.setText("mdb() invoked");
System.out.println("Sending message");
sender.send(tmessage);
System.out.println("message sent");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of javax.jms.QueueSender in project brave by openzipkin.
the class TracingMessageProducer method send.
@Override
public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
checkQueueSender();
QueueSender qs = (QueueSender) delegate;
Span span = createAndStartProducerSpan(message, destination(message));
SpanInScope ws = tracer.withSpanInScope(span);
Throwable error = null;
try {
qs.send(queue, message, deliveryMode, priority, timeToLive);
} catch (Throwable t) {
propagateIfFatal(t);
error = t;
throw t;
} finally {
if (error != null)
span.error(error);
span.finish();
ws.close();
}
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class MessageListenerTransactionIT method testSerialInvocation.
@Test
public void testSerialInvocation() throws Exception {
final long sleep = 100;
TestListener listener = new TestListener(expectedTotalCount, sleep);
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(true, /*transacted*/
Session.CLIENT_ACKNOWLEDGE);
/*ignored*/
Queue[] queues = new Queue[DESTINATIONS.length];
for (int i = 0; i < DESTINATIONS.length; ++i) {
queues[i] = queueSession.createQueue(QUEUE_NAME + DESTINATIONS[i]);
}
MessageConsumer[] consumers = new MessageConsumer[DESTINATIONS.length];
for (int i = 0; i < DESTINATIONS.length; ++i) {
consumers[i] = queueSession.createReceiver(queues[i]);
consumers[i].setMessageListener(listener);
}
QueueSender[] senders = new QueueSender[DESTINATIONS.length];
for (int i = 0; i < DESTINATIONS.length; ++i) {
senders[i] = queueSession.createSender(queues[i]);
senders[i].setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = queueSession.createTextMessage(MESSAGE + DESTINATIONS[i]);
for (int j = 0; j < sendCount; ++j) senders[i].send(message);
}
for (int i = 0; i < DESTINATIONS.length; ++i) senders[i].close();
queueSession.commit();
// wait for the messages to be received; max wait time expectedTotalCount*sleep*2
long maxWait = expectedTotalCount * sleep * 2;
synchronized (listener) {
int rcvd;
while (maxWait > 0 && (rcvd = listener.getReceived()) < expectedTotalCount) {
long startWait = System.currentTimeMillis();
// wait for a bit more
listener.wait((expectedTotalCount - rcvd) * sleep);
maxWait -= (System.currentTimeMillis() - startWait);
}
}
for (int i = 0; i < DESTINATIONS.length; ++i) consumers[i].close();
// acknowledge the messages
Message last = listener.getMessage();
if (last != null) {
last.acknowledge();
}
if (listener.getFailures() != 0) {
fail("The listener was not invoked serially");
}
if (listener.getReceived() != expectedTotalCount) {
fail("Received " + listener.getReceived() + " messages, but expected " + expectedTotalCount);
}
}
Aggregations