use of javax.jms.QueueSender in project activemq-artemis by apache.
the class SimpleOpenWireTest method testTempQueueDelete.
@Test
public void testTempQueueDelete() throws Exception {
connection.start();
QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQueue = queueSession.createTemporaryQueue();
ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection();
try {
QueueSession newQueueSession = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = newQueueSession.createSender(tempQueue);
Message msg = queueSession.createMessage();
queueSender.send(msg);
try {
QueueReceiver consumer = newQueueSession.createReceiver(tempQueue);
fail("should have gotten exception but got consumer: " + consumer);
} catch (JMSException ex) {
// correct
}
connection.close();
try {
Message newMsg = newQueueSession.createMessage();
queueSender.send(newMsg);
} catch (JMSException e) {
// ok
}
} finally {
newConn.close();
}
}
use of javax.jms.QueueSender in project OpenOLAT by OpenOLAT.
the class JmsIndexer method indexDocument.
@Override
public void indexDocument(String type, Long key) {
QueueSender sender;
QueueSession session;
try {
JmsIndexWork workUnit = new JmsIndexWork(JmsIndexWork.INDEX, type, key);
session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
ObjectMessage message = session.createObjectMessage();
message.setObject(workUnit);
sender = session.createSender(getJmsQueue());
sender.send(message);
session.close();
} catch (JMSException e) {
log.error("", e);
}
}
use of javax.jms.QueueSender in project ofbiz-framework by apache.
the class JmsServiceEngine method runXaQueue.
protected Map<String, Object> runXaQueue(ModelService modelService, Map<String, Object> context, Element server) throws GenericServiceException {
String serverName = server.getAttribute("jndi-server-name");
String jndiName = server.getAttribute("jndi-name");
String queueName = server.getAttribute("topic-queue");
String userName = server.getAttribute("username");
String password = server.getAttribute("password");
String clientId = server.getAttribute("client-id");
InitialContext jndi = null;
XAQueueConnectionFactory factory = null;
XAQueueConnection con = null;
try {
jndi = JNDIContextFactory.getInitialContext(serverName);
factory = (XAQueueConnectionFactory) jndi.lookup(jndiName);
} catch (GeneralException ge) {
throw new GenericServiceException("Problems getting JNDI InitialContext.", ge.getNested());
} catch (NamingException ne) {
JNDIContextFactory.clearInitialContext(serverName);
try {
jndi = JNDIContextFactory.getInitialContext(serverName);
factory = (XAQueueConnectionFactory) jndi.lookup(jndiName);
} catch (GeneralException ge2) {
throw new GenericServiceException("Problems getting JNDI InitialContext.", ge2.getNested());
} catch (NamingException ne2) {
throw new GenericServiceException("JNDI lookup problems.", ne2);
}
}
try {
con = factory.createXAQueueConnection(userName, password);
if (clientId.length() > 1)
con.setClientID(userName);
con.start();
// enlist the XAResource
XAQueueSession session = con.createXAQueueSession();
XAResource resource = session.getXAResource();
if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE)
TransactionUtil.enlistResource(resource);
Queue queue = (Queue) jndi.lookup(queueName);
QueueSession qSession = session.getQueueSession();
QueueSender sender = qSession.createSender(queue);
// create/send the message
Message message = makeMessage(session, modelService, context);
sender.send(message);
if (TransactionUtil.getStatus() != TransactionUtil.STATUS_ACTIVE)
session.commit();
Debug.logInfo("Message sent.", module);
// close the connections
sender.close();
session.close();
con.close();
} catch (GenericTransactionException gte) {
throw new GenericServiceException("Problems enlisting resource w/ transaction manager.", gte.getNested());
} catch (NamingException ne) {
throw new GenericServiceException("Problems with JNDI lookup.", ne);
} catch (JMSException je) {
throw new GenericServiceException("JMS Internal Error.", je);
}
return ServiceUtil.returnSuccess();
}
use of javax.jms.QueueSender in project ofbiz-framework by apache.
the class JmsServiceEngine method runQueue.
protected Map<String, Object> runQueue(ModelService modelService, Map<String, Object> context, Server server) throws GenericServiceException {
String serverName = server.getJndiServerName();
String jndiName = server.getJndiName();
String queueName = server.getTopicQueue();
String userName = server.getUsername();
String password = server.getPassword();
String clientId = server.getClientId();
InitialContext jndi = null;
QueueConnectionFactory factory = null;
QueueConnection con = null;
try {
jndi = JNDIContextFactory.getInitialContext(serverName);
factory = (QueueConnectionFactory) jndi.lookup(jndiName);
} catch (GeneralException ge) {
throw new GenericServiceException("Problems getting JNDI InitialContext.", ge.getNested());
} catch (NamingException ne) {
JNDIContextFactory.clearInitialContext(serverName);
try {
jndi = JNDIContextFactory.getInitialContext(serverName);
factory = (QueueConnectionFactory) jndi.lookup(jndiName);
} catch (GeneralException ge2) {
throw new GenericServiceException("Problems getting JNDI InitialContext.", ge2.getNested());
} catch (NamingException ne2) {
throw new GenericServiceException("JNDI lookup problem.", ne2);
}
}
try {
con = factory.createQueueConnection(userName, password);
if (clientId != null && clientId.length() > 1)
con.setClientID(clientId);
con.start();
QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) jndi.lookup(queueName);
QueueSender sender = session.createSender(queue);
// create/send the message
Message message = makeMessage(session, modelService, context);
sender.send(message);
if (Debug.verboseOn())
Debug.logVerbose("Sent JMS Message to " + queueName, module);
// close the connections
sender.close();
session.close();
con.close();
} catch (NamingException ne) {
throw new GenericServiceException("Problems with JNDI lookup.", ne);
} catch (JMSException je) {
throw new GenericServiceException("JMS Internal Error.", je);
}
return ServiceUtil.returnSuccess();
}
use of javax.jms.QueueSender in project core by weld.
the class EJBTest method testMdbUsable.
@Test
public void testMdbUsable(Control control) throws Exception {
InitialContext ctx = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup(WildFly8EEResourceManager.TEST_QUEUE_DESTINATION);
QueueSender sender = session.createSender(queue);
sender.send(session.createTextMessage(MESSAGE));
control.getLatch().await();
Assert.assertTrue(control.isMessageDelivered());
Assert.assertTrue(control.isContextSet());
}
Aggregations