use of org.apache.activemq.ActiveMQConnectionFactory in project play-cookbook by spinscale.
the class ActiveMqTest method initialize.
@Before
public void initialize() throws Exception {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, ActiveMQConnection.DEFAULT_BROKER_URL);
receiveConnection = connectionFactory.createTopicConnection();
receiveConnection.start();
receiveSession = receiveConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
receiveTopic = receiveSession.createTopic("playMessages");
receiveSubscriber = receiveSession.createSubscriber(receiveTopic);
sendingConnection = connectionFactory.createTopicConnection();
sendingConnection.start();
sendingSession = sendingConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
sendingTopic = sendingSession.createTopic("playMessages");
sendingPublisher = sendingSession.createPublisher(sendingTopic);
ChatRoom.clean();
}
use of org.apache.activemq.ActiveMQConnectionFactory in project opennms by OpenNMS.
the class SimpleJobPublisher method publishJob.
// Name of the queue we will be sending messages to
// private static String subject = "TESTQUEUE";
@Override
public void publishJob(CollectionJob job, String site) {
try {
// Getting JMS connection from the server and starting it
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
Connection connection = connectionFactory.createConnection();
connection.start();
// JMS messages are sent and received using a Session. We will
// create here a non-transactional session object. If you want
// to use transactions you should set the first parameter to 'true'
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Destination represents here our queue 'TESTQUEUE' on the
// JMS server. You don't have to do anything special on the
// server to create it, it will be created automatically.
Destination destination = session.createQueue(site);
// MessageProducer is used for sending messages (as opposed
// to MessageConsumer which is used for receiving them)
MessageProducer producer = session.createProducer(destination);
// We will send a small text message saying 'Hello' in Japanese
ObjectMessage message = session.createObjectMessage(job);
// Here we are sending the message!
producer.send(message);
logger.info("Sent message '{}'", ((CollectionJob) message.getObject()).toString());
connection.close();
} catch (Exception e) {
logger.error("Exception during Job Publishing, sorry '{}'", e.getMessage());
}
}
use of org.apache.activemq.ActiveMQConnectionFactory in project oxAuth by GluuFederation.
the class ApplicationAuditLogger method tryToEstablishJMSConnectionImpl.
private boolean tryToEstablishJMSConnectionImpl() {
destroy();
Set<String> jmsBrokerURISet = getJmsBrokerURISet();
if (BooleanUtils.isNotTrue(isEnabledOAuthAuditnLogging()) || CollectionUtils.isEmpty(jmsBrokerURISet))
return false;
this.jmsBrokerURISet = new HashSet<String>(jmsBrokerURISet);
this.jmsUserName = getJmsUserName();
this.jmsPassword = getJmsPassword();
Iterator<String> jmsBrokerURIIterator = jmsBrokerURISet.iterator();
StringBuilder uriBuilder = new StringBuilder();
while (jmsBrokerURIIterator.hasNext()) {
String jmsBrokerURI = jmsBrokerURIIterator.next();
uriBuilder.append("tcp://");
uriBuilder.append(jmsBrokerURI);
if (jmsBrokerURIIterator.hasNext())
uriBuilder.append(",");
}
String brokerUrl = BROKER_URL_PREFIX + uriBuilder + BROKER_URL_SUFFIX;
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(this.jmsUserName, this.jmsPassword, brokerUrl);
this.pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);
pooledConnectionFactory.setIdleTimeout(5000);
pooledConnectionFactory.setMaxConnections(10);
pooledConnectionFactory.start();
return true;
}
use of org.apache.activemq.ActiveMQConnectionFactory in project tomee by apache.
the class ActiveMQResourceAdapter method createConnectionFactory.
@Override
protected ActiveMQConnectionFactory createConnectionFactory(final ActiveMQConnectionRequestInfo connectionRequestInfo, final MessageActivationSpec activationSpec) {
if (TomEEMessageActivationSpec.class.isInstance(activationSpec)) {
final TomEEMessageActivationSpec s = TomEEMessageActivationSpec.class.cast(activationSpec);
if (s.getConnectionFactoryLookup() != null) {
try {
final Object lookup = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup("openejb:Resource/" + s.getConnectionFactoryLookup());
if (ActiveMQConnectionFactory.class.isInstance(lookup)) {
return ActiveMQConnectionFactory.class.cast(lookup);
}
// already handled
return ActiveMQConnectionFactory.class.cast(lookup);
} catch (final NamingException e) {
throw new IllegalArgumentException("");
}
}
}
final ActiveMQConnectionFactory factory = new TomEEConnectionFactory();
connectionRequestInfo.configure(factory, activationSpec);
return factory;
}
Aggregations