use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class JMSWebSocketConnectionTest method testSendLargeMessageToClientFromAMQP.
@Ignore("Broker can't accept messages over 65535 right now")
@Test(timeout = 30000)
public void testSendLargeMessageToClientFromAMQP() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
JmsConnection connection = (JmsConnection) factory.createConnection();
sendLargeMessageViaAMQP();
try {
Session session = connection.createSession();
Queue queue = session.createQueue(getQueueName());
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
Message message = consumer.receive(1000);
assertNotNull(message);
assertTrue(message instanceof BytesMessage);
} finally {
connection.close();
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class SaslKrb5LDAPSecurityTest method dotestJAASSecurityManagerAuthorizationPositive.
public void dotestJAASSecurityManagerAuthorizationPositive(String jaasConfigScope, String artemisRoleName) throws Exception {
createArtemisServer(jaasConfigScope);
Set<Role> roles = new HashSet<>();
roles.add(new Role(artemisRoleName, true, true, true, true, true, true, true, true, true, true));
server.getConfiguration().putSecurityRoles(QUEUE_NAME, roles);
server.start();
JmsConnectionFactory jmsConnectionFactory = new JmsConnectionFactory("amqp://localhost:5672?amqp.saslMechanisms=GSSAPI");
Connection connection = jmsConnectionFactory.createConnection("client", null);
try {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(QUEUE_NAME);
// PRODUCE
final String text = RandomUtil.randomString();
try {
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage(text));
} catch (Exception e) {
e.printStackTrace();
Assert.fail("should not throw exception here");
}
// CONSUME
try {
MessageConsumer consumer = session.createConsumer(queue);
TextMessage m = (TextMessage) consumer.receive(1000);
Assert.assertNotNull(m);
Assert.assertEquals(text, m.getText());
} catch (Exception e) {
Assert.fail("should not throw exception here");
}
} finally {
connection.close();
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class AMQPToOpenwireTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
server = createServer(true, true);
server.start();
server.waitForActivation(10, TimeUnit.SECONDS);
Configuration serverConfig = server.getConfiguration();
serverConfig.getAddressesSettings().put("#", new AddressSettings().setAutoCreateQueues(false).setAutoCreateAddresses(false).setDeadLetterAddress(new SimpleString("ActiveMQ.DLQ")));
serverConfig.setSecurityEnabled(false);
coreQueue = new SimpleString(queueName);
server.createQueue(coreQueue, RoutingType.ANYCAST, coreQueue, null, false, false);
qpidfactory = new JmsConnectionFactory("amqp://localhost:61616");
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class AMQPQueueExample method main.
public static void main(String[] args) throws Exception {
Connection connection = null;
ConnectionFactory connectionFactory = new JmsConnectionFactory("amqp://localhost:5672");
try {
// Step 1. Create an amqp qpid 1.0 connection
connection = connectionFactory.createConnection();
// Step 2. Create a session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Step 3. Create a sender
Queue queue = session.createQueue("exampleQueue");
MessageProducer sender = session.createProducer(queue);
// Step 4. send a few simple message
sender.send(session.createTextMessage("Hello world "));
connection.start();
// Step 5. create a moving receiver, this means the message will be removed from the queue
MessageConsumer consumer = session.createConsumer(queue);
// Step 7. receive the simple message
TextMessage m = (TextMessage) consumer.receive(5000);
System.out.println("message = " + m.getText());
} finally {
if (connection != null) {
// Step 9. close the connection
connection.close();
}
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class AMQPMessageLoadBalancingTest method testLoadBalanceAMQP.
@Test
public void testLoadBalanceAMQP() throws Exception {
setupCluster(MessageLoadBalancingType.STRICT);
startServers(0, 1);
setupSessionFactory(0, isNetty());
setupSessionFactory(1, isNetty());
createQueue(0, "queues.0", "queues.0", null, true, null, null, RoutingType.ANYCAST);
createQueue(1, "queues.0", "queues.0", null, true, null, null, RoutingType.ANYCAST);
waitForBindings(0, "queues.0", 1, 0, true);
waitForBindings(1, "queues.0", 1, 0, true);
waitForBindings(0, "queues.0", 1, 0, false);
waitForBindings(1, "queues.0", 1, 0, false);
final int NUMBER_OF_MESSAGES = 100;
// sending AMQP Messages.. they should be load balanced
{
JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
Connection connection = factory.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer producer = session.createProducer(session.createQueue("queues.0"));
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
producer.send(session.createTextMessage("hello " + i));
}
session.commit();
connection.close();
}
receiveOnBothNodes(NUMBER_OF_MESSAGES);
// If a user used a message type = 7, for messages that are not embedded,
// it should still be treated as a normal message
{
ClientSession sessionProducer = sfs[0].createSession();
ClientProducer producer = sessionProducer.createProducer("queues.0");
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
// The user is mistakenly using the same type we used for embedded messages. it should still work
ClientMessage message = sessionProducer.createMessage(Message.EMBEDDED_TYPE, true).putIntProperty("i", i);
message.getBodyBuffer().writeString("hello!");
producer.send(message);
// will send 2 messages.. one with stuff, another empty
message = sessionProducer.createMessage(Message.EMBEDDED_TYPE, true);
producer.send(message);
}
receiveOnBothNodes(NUMBER_OF_MESSAGES * 2);
}
}
Aggregations