use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.
the class AsyncConsumerFalseTest method createCamelContext.
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
camelContext.addComponent("async", new MyAsyncComponent());
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://broker?broker.persistent=false&broker.useJmx=false");
SjmsComponent component = new SjmsComponent();
component.setConnectionFactory(connectionFactory);
camelContext.addComponent("sjms", component);
return camelContext;
}
use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.
the class MyApplication method setupCamelContext.
@Override
protected void setupCamelContext(CamelContext camelContext) throws Exception {
// setup the ActiveMQ component
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL("vm://localhost?broker.persistent=false&broker.useJmx=false");
// and register it into the CamelContext
JmsComponent answer = new JmsComponent();
answer.setConnectionFactory(connectionFactory);
camelContext.addComponent("jms", answer);
}
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 beam by apache.
the class JmsIOTest method startBroker.
@Before
public void startBroker() throws Exception {
broker = new BrokerService();
broker.setUseJmx(false);
broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
broker.addConnector(BROKER_URL);
broker.setBrokerName("localhost");
broker.setPopulateJMSXUserID(true);
broker.setUseAuthenticatedPrincipalForJMSXUserID(true);
// enable authentication
List<AuthenticationUser> users = new ArrayList<>();
// username and password to use to connect to the broker.
// This user has users privilege (able to browse, consume, produce, list destinations)
users.add(new AuthenticationUser(USERNAME, PASSWORD, "users"));
SimpleAuthenticationPlugin plugin = new SimpleAuthenticationPlugin(users);
BrokerPlugin[] plugins = new BrokerPlugin[] { plugin };
broker.setPlugins(plugins);
broker.start();
// create JMS connection factory
connectionFactory = new ActiveMQConnectionFactory(BROKER_URL);
connectionFactoryWithoutPrefetch = new ActiveMQConnectionFactory(BROKER_URL + "?jms.prefetchPolicy.all=0");
}
Aggregations