use of javax.jms.QueueConnection in project oxAuth by GluuFederation.
the class ApplicationAuditLogger method loggingThroughJMS.
private void loggingThroughJMS(OAuth2AuditLog oAuth2AuditLog) {
QueueConnection connection = null;
try {
connection = pooledConnectionFactory.createQueueConnection();
connection.start();
QueueSession session = connection.createQueueSession(transacted, ACK_MODE);
MessageProducer producer = session.createProducer(session.createQueue(CLIENT_QUEUE_NAME));
TextMessage txtMessage = session.createTextMessage();
txtMessage.setText(ServerUtil.asPrettyJson(oAuth2AuditLog));
producer.send(txtMessage);
} catch (JMSException e) {
log.error("Can't send message", e);
} catch (IOException e) {
log.error("Can't serialize the audit log", e);
} catch (Exception e) {
log.error("Can't send message, please check your activeMQ configuration.", e);
} finally {
if (connection == null)
return;
try {
connection.close();
} catch (JMSException e) {
log.error("Can't close connection.");
}
}
}
use of javax.jms.QueueConnection in project karaf by apache.
the class ArtemisDestinationSourceFactory method getNames.
private List<String> getNames(Connection connection, DestinationSource.DestinationType type) {
try {
QueueSession session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue managementQueue = session.createQueue("activemq.management");
QueueRequestor requestor = new QueueRequestor(session, managementQueue);
connection.start();
TextMessage m = session.createTextMessage();
m.setStringProperty("_AMQ_ResourceName", "broker");
m.setStringProperty("_AMQ_OperationName", "getQueueNames");
String routing = type == DestinationSource.DestinationType.Queue ? "ANYCAST" : "MULTICAST";
m.setText("[\"" + routing + "\"]");
Message reply = requestor.request(m);
String json = ((TextMessage) reply).getText();
List<?> array = (List<?>) JsonReader.read(new StringReader(json));
return (List<String>) array.get(0);
} catch (Exception e) {
return Collections.emptyList();
}
}
use of javax.jms.QueueConnection 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.QueueConnection 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.QueueConnection in project iaf by ibissource.
the class MessagingSource method createSession.
public Session createSession(boolean transacted, int acknowledgeMode) throws IbisException {
Connection connection = null;
;
Session session;
try {
connection = getConnection();
} catch (JMSException e) {
throw new JmsException("could not obtain Connection", e);
}
try {
// if (log.isDebugEnabled()) log.debug(getLogPrefix()+"creating Session, openSessionCount before ["+openSessionCount.getValue()+"]");
if (useJms102()) {
if (connection instanceof QueueConnection) {
session = ((QueueConnection) connection).createQueueSession(transacted, acknowledgeMode);
} else {
session = ((TopicConnection) connection).createTopicSession(transacted, acknowledgeMode);
}
} else {
session = connection.createSession(transacted, acknowledgeMode);
}
openSessionCount.increase();
if (connectionsArePooled()) {
connectionTable.put(session, connection);
}
return session;
} catch (JMSException e) {
releaseConnection(connection);
throw new JmsException("could not create Session", e);
}
}
Aggregations