use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class ConnectionAbstract method createAMQPConnectionFactory.
private ConnectionFactory createAMQPConnectionFactory() {
if (brokerURL.startsWith("tcp://")) {
// replacing tcp:// by amqp://
brokerURL = "amqp" + brokerURL.substring(3);
}
JmsConnectionFactory cf = new JmsConnectionFactory(user, password, brokerURL);
if (clientID != null) {
cf.setClientID(clientID);
}
try {
Connection connection = cf.createConnection();
connection.close();
return cf;
} catch (JMSSecurityException e) {
// if a security exception will get the user and password through an input
context.err.println("Connection failed::" + e.getMessage());
userPassword();
return new JmsConnectionFactory(user, password, brokerURL);
} catch (JMSException e) {
// if a connection exception will ask for the URL, user and password
context.err.println("Connection failed::" + e.getMessage());
brokerURL = input("--url", "Type in the broker URL for a retry (e.g. tcp://localhost:61616)", brokerURL);
userPassword();
return new JmsConnectionFactory(user, password, brokerURL);
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class JMSWebSocketConnectionTest method testSendReceiveOverWS.
@Test(timeout = 30000)
public void testSendReceiveOverWS() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
JmsConnection connection = (JmsConnection) factory.createConnection();
try {
Session session = connection.createSession();
Queue queue = session.createQueue(getQueueName());
MessageProducer producer = session.createProducer(queue);
producer.send(session.createMessage());
producer.close();
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
Message message = consumer.receive(1000);
assertNotNull(message);
} finally {
connection.close();
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class JMSWebSocketConnectionTest method sendLargeMessageViaAMQP.
protected void sendLargeMessageViaAMQP() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
doSendLargeMessageViaOpenWire(factory.createConnection());
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class SyncSendTest method newCF.
// this will set ack as synchronous, to make sure we make proper measures against the sync on disk
private ConnectionFactory newCF() {
if (protocol.equals("core")) {
ConnectionFactory factory = new ActiveMQConnectionFactory();
((ActiveMQConnectionFactory) factory).setBlockOnAcknowledge(true);
return factory;
} else if (protocol.equals("amqp")) {
final JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
factory.setForceAsyncAcks(true);
return factory;
} else {
org.apache.activemq.ActiveMQConnectionFactory cf = new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616?wireFormat.cacheEnabled=true");
cf.setSendAcksAsync(false);
return cf;
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class ProtonCPPExample method main.
public static void main(final String[] args) throws Exception {
Connection connection = null;
InitialContext initialContext = null;
try {
// Create an initial context to perform the JNDI lookup.
initialContext = new InitialContext();
// if you wanted to use Core JMS, use this line instead.
// ConnectionFactory cf = new ActiveMQConnectionFactory();
ConnectionFactory cf = new JmsConnectionFactory("amqp://localhost:61616");
// Create a the JMS objects
connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Perform the look-ups
Queue queue = session.createQueue("exampleQueue");
MessageConsumer messageConsumer = session.createConsumer(queue);
MessageProducer producerAnswer = session.createProducer(queue);
// Start the connection
connection.start();
System.out.println("On a shell script, execute the following:");
System.out.println("./compile.sh");
System.out.println("./hello");
for (int i = 0; i < 10; i++) {
try {
// Step 5. Finally, receive the message
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
if (messageReceived == null) {
System.out.println("No messages");
// We are not going to issue this as an error because
// we also use this example as part of our tests on artemis
// this is not considered an error, just that no messages arrived (i.e. hello wasn't called)
} else {
System.out.println("message received: " + messageReceived.getText());
// Sending message back to client
producerAnswer.send(session.createTextMessage("HELLO from Apache ActiveMQ Artemis " + i + "!!"));
}
} catch (Throwable e) {
e.printStackTrace();
}
}
} finally {
// Step 9. Be sure to close our resources!
if (initialContext != null) {
initialContext.close();
}
if (connection != null) {
connection.close();
}
}
}
Aggregations