use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class SimpleJNDIClientTest method testRemoteCFWithTCPUserPassword.
@Test
public void testRemoteCFWithTCPUserPassword() throws Exception {
// setup user and role on broker
((ActiveMQJAASSecurityManager) liveService.getSecurityManager()).getConfiguration().addUser("myUser", "myPassword");
((ActiveMQJAASSecurityManager) liveService.getSecurityManager()).getConfiguration().addRole("myUser", "consumeCreateRole");
Role consumeCreateRole = new Role("consumeCreateRole", false, true, true, true, true, true, true, true, true, true);
Set<Role> consumerCreateRoles = new HashSet<>();
consumerCreateRoles.add(consumeCreateRole);
liveService.getSecurityRepository().addMatch("test.queue", consumerCreateRoles);
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
// user and password set on URL
props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:61616?user=myUser&password=myPassword");
Context ctx = new InitialContext(props);
// create a connection factory
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
Assert.assertEquals("ensure user is set", "myUser", connectionFactory.getUser());
Assert.assertEquals("ensure password is set", "myPassword", connectionFactory.getPassword());
// Connect to broker to verify credentials are used with connection
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue("test.queue");
try {
try {
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("test Msg"));
Assert.fail("Sending message should throw a JMSSecurityException");
} catch (JMSSecurityException e) {
// expected
}
MessageConsumer consumer = session.createConsumer(queue);
} finally {
connection.close();
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class URITest method testParseURIs.
@Test
public void testParseURIs() throws Throwable {
ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false", "some name");
Assert.assertEquals(2, ((ServerLocatorImpl) factory.getServerLocator()).getInitialConnectors().length);
ActiveMQConnectionFactory factory2 = new ActiveMQConnectionFactory("(tcp://localhost:61614,tcp://localhost:61616)?blockOnDurableSend=false");
Assert.assertEquals(2, ((ServerLocatorImpl) factory2.getServerLocator()).getInitialConnectors().length);
ServerLocator locator = ServerLocatorImpl.newLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false");
Assert.assertEquals(2, ((ServerLocatorImpl) locator).getInitialConnectors().length);
ServerLocator locator2 = ActiveMQClient.createServerLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false");
Assert.assertEquals(2, ((ServerLocatorImpl) locator2).getInitialConnectors().length);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class ConnectionTest method testTwoConnectionsSameIDThroughCF.
@Test
public void testTwoConnectionsSameIDThroughCF() throws Exception {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?clientID=myid");
conn = connectionFactory.createConnection();
try {
conn2 = connectionFactory.createConnection();
Assert.fail("Exception expected");
} catch (InvalidClientIDException expected) {
// expected
}
Session session1 = conn.createSession();
Session session2 = conn.createSession();
session1.close();
session2.close();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class GroupingTest method testGroupingRollbackOnClose.
@Test
public void testGroupingRollbackOnClose() throws Exception {
ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();
fact.setConsumerWindowSize(1000);
fact.setTransactionBatchSize(0);
Connection connection = fact.createConnection();
RemotingConnection rc = server.getRemotingService().getConnections().iterator().next();
Connection connection2 = fact.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Session session2 = connection2.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer producer = session.createProducer(queue);
MessageConsumer consumer1 = session.createConsumer(queue);
MessageConsumer consumer2 = session2.createConsumer(queue);
connection.start();
connection2.start();
String jmsxgroupID = null;
for (int j = 0; j < 100; j++) {
TextMessage message = session.createTextMessage();
message.setText("Message" + j);
setProperty(message);
producer.send(message);
String prop = message.getStringProperty("JMSXGroupID");
assertNotNull(prop);
if (jmsxgroupID != null) {
assertEquals(jmsxgroupID, prop);
} else {
jmsxgroupID = prop;
}
}
session.commit();
// consume 5 msgs from 1st first consumer
for (int j = 0; j < 1; j++) {
TextMessage tm = (TextMessage) consumer1.receive(10000);
assertNotNull(tm);
assertEquals("Message" + j, tm.getText());
assertEquals(tm.getStringProperty("JMSXGroupID"), jmsxgroupID);
}
Thread.sleep(2000);
// session.rollback();
// session.close();
// consume all msgs from 2nd first consumer
// ClientSession amqs = ((ActiveMQSession) session).getCoreSession();
// ((DelegatingSession) amqs).getChannel().close();
rc.fail(new ActiveMQNotConnectedException());
for (int j = 0; j < 10; j++) {
TextMessage tm = (TextMessage) consumer2.receive(10000);
assertNotNull(tm);
long text = ((ActiveMQTextMessage) tm).getCoreMessage().getMessageID();
System.out.println(tm.getJMSMessageID() + " text = " + text);
// assertEquals("Message" + j, text);
assertEquals(tm.getStringProperty("JMSXGroupID"), jmsxgroupID);
}
connection.close();
connection2.close();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class GroupingTest method testManyGroups.
@Test
public void testManyGroups() throws Exception {
ConnectionFactory fact = getCF();
Assume.assumeFalse("only makes sense withOUT auto-group", ((ActiveMQConnectionFactory) fact).isAutoGroup());
Connection connection = fact.createConnection();
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
MessageConsumer consumer1 = session.createConsumer(queue);
MessageConsumer consumer2 = session.createConsumer(queue);
MessageConsumer consumer3 = session.createConsumer(queue);
connection.start();
for (int j = 0; j < 1000; j++) {
TextMessage message = session.createTextMessage();
message.setText("Message" + j);
message.setStringProperty("_AMQ_GROUP_ID", "" + (j % 10));
producer.send(message);
String prop = message.getStringProperty("JMSXGroupID");
assertNotNull(prop);
}
int msg1 = flushMessages(consumer1);
int msg2 = flushMessages(consumer2);
int msg3 = flushMessages(consumer3);
assertNotSame(0, msg1);
assertNotSame(0, msg2);
assertNotSame(0, msg2);
consumer1.close();
consumer2.close();
consumer3.close();
connection.close();
}
Aggregations