use of org.apache.activemq.ActiveMQConnectionFactory in project hive by apache.
the class TestMsgBusConnection method connectClient.
private void connectClient() throws JMSException {
ConnectionFactory connFac = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection conn = connFac.createConnection();
conn.start();
Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
Destination hcatTopic = session.createTopic("planetlab.hcat");
consumer = session.createConsumer(hcatTopic);
}
use of org.apache.activemq.ActiveMQConnectionFactory in project pinpoint by naver.
the class TestBroker method start.
boolean start() throws Exception {
this.brokerService.start();
// but this method was only introduced in 5.3.0
for (Map.Entry<String, ActiveMQConnectionFactory> e : this.connectionFactories.entrySet()) {
String connectUri = e.getKey();
ActiveMQConnectionFactory connectionFactory = e.getValue();
ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
connection.setClientID("client_" + connectUri);
connection.start();
this.connections.put(connectUri, connection);
}
return true;
}
use of org.apache.activemq.ActiveMQConnectionFactory in project adempiere by adempiere.
the class TopicExportProcessor method sendJMSMessage.
private void sendJMSMessage(String host, int port, String msg, String protocol, String topicName, String clientID, String userName, String password, int timeToLive, boolean isDeliveryModePersistent) throws JMSException {
// Create a ConnectionFactory
// network protocol (tcp, ...) set as EXP_ProcessorParameter
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(protocol + "://" + host + ":" + port);
Connection connection = null;
Session session = null;
try {
// Create a Connection
if (userName != null && password != null) {
connection = connectionFactory.createConnection(userName, password);
} else {
connection = connectionFactory.createConnection();
}
// connection.setClientID( clientID ); Commented by Victor as he had issue!
connection.start();
// Create a Session
//TODO - Trifon could be EXP_ProcessorParameter
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createTopic(topicName);
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
// EXP_ProcessorParameter
producer.setTimeToLive(timeToLive);
if (isDeliveryModePersistent) {
// EXP_ProcessorParameter
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
} else {
// EXP_ProcessorParameter
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
// How to send to multiple destinations.
//MessageProducer producer = session.createProducer(null);
//producer.send(someDestination, message);
//producer.send(anotherDestination, message);
// Create a message
TextMessage message = session.createTextMessage(msg);
// Tell the producer to send the message
try {
producer.send(message);
session.commit();
log.info("JMS Message sent!");
} catch (JMSException ex) {
session.rollback();
log.info("JMS Can't send the message!");
throw ex;
}
} finally {
// Clean up
if (session != null) {
try {
session.close();
} catch (JMSException ex) {
/* ignored */
}
}
if (connection != null) {
try {
connection.close();
} catch (JMSException ex) {
/* ignored */
}
}
}
}
use of org.apache.activemq.ActiveMQConnectionFactory in project adempiere by adempiere.
the class TopicListener method run.
public void run() throws JMSException {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
log.finest("ActiveMQConnectionFactory = " + factory);
if (userName != null && password != null) {
conn = factory.createConnection(userName, password);
} else {
conn = factory.createConnection();
}
log.finest("conn = " + conn);
if (conn.getClientID() == null) {
try {
conn.setClientID(clientID);
} catch (Exception e) {
//log.info("Connection with clientID '" + clientID +"' already exists" + e.toString());
conn.close();
return;
}
} else {
if (conn.getClientID().equals(clientID)) {
log.warning("Connection with clientID '" + clientID + "' already exists");
conn.close();
return;
} else {
try {
conn.setClientID(clientID);
} catch (Exception e) {
log.info("Error while invoking setClientID(" + clientID + ")! " + e.getMessage());
conn.close();
return;
}
}
}
// TODO - could be parameter
session = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
log.finest("session = " + session);
log.finest("topicName = " + topicName);
log.finest("subscriptionName = " + subscriptionName);
topic = session.createTopic(topicName);
log.finest("topic = " + topic);
MessageConsumer consumer = null;
if (isDurableSubscription) {
// http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.pmc.express.doc/tasks/tjn0012_.html
// The subscriptionName assigned to a durable subscription must be unique within a given client ID.
consumer = session.createDurableSubscriber(topic, subscriptionName);
} else {
consumer = session.createConsumer(topic);
}
log.finest("consumer = " + consumer);
consumer.setMessageListener(this);
conn.start();
log.finest("Waiting for JMS messages...");
if (replicationProcessor != null) {
MIMPProcessorLog pLog = new MIMPProcessorLog(replicationProcessor.getMImportProcessor(), "Connected to JMS Server. Waiting for messages!");
StringBuffer logReference = new StringBuffer("topicName = ").append(topicName).append(", subscriptionName = ").append(subscriptionName);
pLog.setReference(logReference.toString());
boolean resultSave = pLog.save();
log.finest("Result Save = " + resultSave);
}
}
use of org.apache.activemq.ActiveMQConnectionFactory in project spring-boot by spring-projects.
the class ActiveMQAutoConfigurationTests method brokerIsEmbeddedByDefault.
@Test
public void brokerIsEmbeddedByDefault() {
load(EmptyConfiguration.class);
ConnectionFactory connectionFactory = this.context.getBean(ConnectionFactory.class);
assertThat(connectionFactory).isInstanceOf(ActiveMQConnectionFactory.class);
String brokerUrl = ((ActiveMQConnectionFactory) connectionFactory).getBrokerURL();
assertThat(brokerUrl).isEqualTo("vm://localhost?broker.persistent=false");
}
Aggregations