use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testListQueuesOrder.
@Test
public void testListQueuesOrder() throws Exception {
SimpleString queueName1 = new SimpleString("my_queue_1");
SimpleString queueName2 = new SimpleString("my_queue_2");
SimpleString queueName3 = new SimpleString("my_queue_3");
ActiveMQServerControl serverControl = createManagementControl();
server.addAddressInfo(new AddressInfo(queueName1, RoutingType.ANYCAST));
server.createQueue(queueName1, RoutingType.ANYCAST, queueName1, new SimpleString("filter1"), null, true, false, false, 20, false, false);
Thread.sleep(500);
server.addAddressInfo(new AddressInfo(queueName2, RoutingType.ANYCAST));
server.createQueue(queueName2, RoutingType.ANYCAST, queueName2, new SimpleString("filter3"), null, true, false, true, 40, false, false);
Thread.sleep(500);
server.addAddressInfo(new AddressInfo(queueName3, RoutingType.ANYCAST));
server.createQueue(queueName3, RoutingType.ANYCAST, queueName3, new SimpleString("filter0"), null, true, false, false, 10, false, false);
// test default order
String filterString = createJsonFilter("name", "CONTAINS", "my_queue");
String queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
JsonObject queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
JsonArray array = (JsonArray) queuesAsJsonObject.get("data");
Assert.assertEquals("number of queues returned from query", 3, array.size());
Assert.assertEquals("queue1 default Order", queueName1.toString(), array.getJsonObject(0).getString("name"));
Assert.assertEquals("queue2 default Order", queueName2.toString(), array.getJsonObject(1).getString("name"));
Assert.assertEquals("queue3 default Order", queueName3.toString(), array.getJsonObject(2).getString("name"));
// test ordered by id desc
filterString = createJsonFilter("name", "CONTAINS", "my_queue", "id", "desc");
queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
array = (JsonArray) queuesAsJsonObject.get("data");
Assert.assertEquals("number of queues returned from query", 3, array.size());
Assert.assertEquals("queue3 ordered by id", queueName3.toString(), array.getJsonObject(0).getString("name"));
Assert.assertEquals("queue2 ordered by id", queueName2.toString(), array.getJsonObject(1).getString("name"));
Assert.assertEquals("queue1 ordered by id", queueName1.toString(), array.getJsonObject(2).getString("name"));
// ordered by address desc
filterString = createJsonFilter("name", "CONTAINS", "my_queue", "address", "desc");
queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
array = (JsonArray) queuesAsJsonObject.get("data");
Assert.assertEquals("number of queues returned from query", 3, array.size());
Assert.assertEquals("queue3 ordered by address", queueName3.toString(), array.getJsonObject(0).getString("name"));
Assert.assertEquals("queue2 ordered by address", queueName2.toString(), array.getJsonObject(1).getString("name"));
Assert.assertEquals("queue1 ordered by address", queueName1.toString(), array.getJsonObject(2).getString("name"));
// ordered by auto create desc
filterString = createJsonFilter("name", "CONTAINS", "my_queue", "autoCreated", "asc");
queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
array = (JsonArray) queuesAsJsonObject.get("data");
Assert.assertEquals("number of queues returned from query", 3, array.size());
Assert.assertEquals("pos1 ordered by autocreate", "false", array.getJsonObject(0).getString("autoCreated"));
Assert.assertEquals("pos2 ordered by autocreate", "false", array.getJsonObject(1).getString("autoCreated"));
Assert.assertEquals("pos3 ordered by autocreate", "true", array.getJsonObject(2).getString("autoCreated"));
// ordered by filter desc
filterString = createJsonFilter("name", "CONTAINS", "my_queue", "filter", "desc");
queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
array = (JsonArray) queuesAsJsonObject.get("data");
Assert.assertEquals("number of queues returned from query", 3, array.size());
Assert.assertEquals("queue2 ordered by filter", queueName2.toString(), array.getJsonObject(0).getString("name"));
Assert.assertEquals("queue1 ordered by filter", queueName1.toString(), array.getJsonObject(1).getString("name"));
Assert.assertEquals("queue3 ordered by filter", queueName3.toString(), array.getJsonObject(2).getString("name"));
// ordered by max consumers asc
filterString = createJsonFilter("name", "CONTAINS", "my_queue", "maxConsumers", "asc");
queuesAsJsonString = serverControl.listQueues(filterString, 1, 50);
queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
array = (JsonArray) queuesAsJsonObject.get("data");
Assert.assertEquals("number of queues returned from query", 3, array.size());
Assert.assertEquals("queue3 ordered by filter", queueName3.toString(), array.getJsonObject(0).getString("name"));
Assert.assertEquals("queue1 ordered by filter", queueName1.toString(), array.getJsonObject(1).getString("name"));
Assert.assertEquals("queue2 ordered by filter", queueName2.toString(), array.getJsonObject(2).getString("name"));
// ordering between the pages
// page 1
filterString = createJsonFilter("name", "CONTAINS", "my_queue", "address", "desc");
queuesAsJsonString = serverControl.listQueues(filterString, 1, 1);
queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
array = (JsonArray) queuesAsJsonObject.get("data");
Assert.assertEquals("number of queues returned from query", 1, array.size());
Assert.assertEquals("queue3 ordered by page", queueName3.toString(), array.getJsonObject(0).getString("name"));
// page 2
filterString = createJsonFilter("name", "CONTAINS", "my_queue", "address", "desc");
queuesAsJsonString = serverControl.listQueues(filterString, 2, 1);
queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
array = (JsonArray) queuesAsJsonObject.get("data");
Assert.assertEquals("number of queues returned from query", 1, array.size());
Assert.assertEquals("queue2 ordered by page", queueName2.toString(), array.getJsonObject(0).getString("name"));
// page 3
filterString = createJsonFilter("name", "CONTAINS", "my_queue", "address", "desc");
queuesAsJsonString = serverControl.listQueues(filterString, 3, 1);
queuesAsJsonObject = JsonUtil.readJsonObject(queuesAsJsonString);
array = (JsonArray) queuesAsJsonObject.get("data");
Assert.assertEquals("number of queues returned from query", 1, array.size());
Assert.assertEquals("queue1 ordered by page", queueName1.toString(), array.getJsonObject(0).getString("name"));
}
use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testListProducers.
@Test
public void testListProducers() throws Exception {
SimpleString queueName1 = new SimpleString("my_queue_one");
SimpleString addressName1 = new SimpleString("my_address_one");
ActiveMQServerControl serverControl = createManagementControl();
server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST));
server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false);
// create some consumers
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSession session1 = csf.createSession();
ClientSession session2 = csf.createSession();
ClientProducer producer1 = session1.createProducer(addressName1);
ClientProducer producer2 = session1.createProducer(addressName1);
// bring back all producers
String filterString = createJsonFilter("", "", "");
String producersAsJsonString = serverControl.listProducers(filterString, 1, 50);
JsonObject producersAsJsonObject = JsonUtil.readJsonObject(producersAsJsonString);
JsonArray array = (JsonArray) producersAsJsonObject.get("data");
Assert.assertTrue("number of producers returned from query", 2 <= array.size());
JsonObject jsonSession = array.getJsonObject(0);
// check all fields
Assert.assertNotEquals("id", "", jsonSession.getString("id"));
Assert.assertNotEquals("session", "", jsonSession.getString("session"));
Assert.assertEquals("clientID", "", jsonSession.getString("clientID"));
Assert.assertEquals("user", "", jsonSession.getString("user"));
Assert.assertNotEquals("protocol", "", jsonSession.getString("protocol"));
Assert.assertEquals("address", "", jsonSession.getString("address"));
Assert.assertNotEquals("localAddress", "", jsonSession.getString("localAddress"));
Assert.assertNotEquals("remoteAddress", "", jsonSession.getString("remoteAddress"));
Assert.assertNotEquals("creationTime", "", jsonSession.getString("creationTime"));
}
}
use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.
the class ManagementServiceImpl method start.
// ActiveMQComponent implementation -----------------------------
@Override
public void start() throws Exception {
if (messageCounterEnabled) {
messageCounterManager.start();
}
started = true;
/**
* Ensure the management notification address is created otherwise if auto-create-address = false then cluster
* bridges won't be able to connect.
*/
messagingServer.registerActivateCallback(new ActivateCallback() {
@Override
public void activated() {
try {
messagingServer.addAddressInfo(new AddressInfo(managementNotificationAddress, RoutingType.MULTICAST));
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.unableToCreateManagementNotificationAddress(managementNotificationAddress, e);
}
}
});
}
use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.
the class SymmetricClusterTest method testBasicRoundRobinManyMessagesNoAddressAutoCreate.
@Test
public void testBasicRoundRobinManyMessagesNoAddressAutoCreate() throws Exception {
setupCluster();
startServers();
for (int i = 0; i < 5; i++) {
servers[i].getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false).setAutoCreateQueues(false));
}
for (int i = 0; i < 5; i++) {
setupSessionFactory(i, isNetty());
}
for (int i = 0; i < 5; i++) {
servers[i].addAddressInfo(new AddressInfo(SimpleString.toSimpleString("queues.testaddress"), RoutingType.MULTICAST));
createQueue(i, "queues.testaddress", "queue0", null, false);
}
for (int i = 0; i < 5; i++) {
addConsumer(i, i, "queue0", null);
}
for (int i = 0; i < 5; i++) {
waitForBindings(i, "queues.testaddress", 1, 1, true);
}
for (int i = 0; i < 5; i++) {
waitForBindings(i, "queues.testaddress", 4, 4, false);
}
send(0, "queues.testaddress", 1000, true, null);
verifyReceiveRoundRobinInSomeOrder(1000, 0, 1, 2, 3, 4);
verifyNotReceive(0, 1, 2, 3, 4);
}
use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.
the class SecurityTest method testJAASSecurityManagerAuthorizationNegativeWithCerts.
@Test
public void testJAASSecurityManagerAuthorizationNegativeWithCerts() throws Exception {
final SimpleString ADDRESS = new SimpleString("address");
final SimpleString DURABLE_QUEUE = new SimpleString("durableQueue");
final SimpleString NON_DURABLE_QUEUE = new SimpleString("nonDurableQueue");
ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("CertLogin");
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false));
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
params.put(TransportConstants.KEYSTORE_PATH_PROP_NAME, "server-side-keystore.jks");
params.put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "secureexample");
params.put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "server-side-truststore.jks");
params.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "secureexample");
params.put(TransportConstants.NEED_CLIENT_AUTH_PROP_NAME, true);
server.getConfiguration().addAcceptorConfiguration(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY, params));
Set<Role> roles = new HashSet<>();
roles.add(new Role("programmers", false, false, false, false, false, false, false, false, false, false));
server.getConfiguration().putSecurityRoles("#", roles);
server.start();
TransportConfiguration tc = new TransportConfiguration(NETTY_CONNECTOR_FACTORY);
tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
tc.getParams().put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "client-side-truststore.jks");
tc.getParams().put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "secureexample");
tc.getParams().put(TransportConstants.KEYSTORE_PATH_PROP_NAME, "client-side-keystore.jks");
tc.getParams().put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "secureexample");
ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc));
ClientSessionFactory cf = createSessionFactory(locator);
server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
server.createQueue(ADDRESS, RoutingType.ANYCAST, DURABLE_QUEUE, null, true, false);
server.createQueue(ADDRESS, RoutingType.ANYCAST, NON_DURABLE_QUEUE, null, false, false);
ClientSession session = addClientSession(cf.createSession());
// CREATE_DURABLE_QUEUE
try {
session.createQueue(ADDRESS, DURABLE_QUEUE, true);
Assert.fail("should throw exception here");
} catch (ActiveMQException e) {
// ignore
}
// DELETE_DURABLE_QUEUE
try {
session.deleteQueue(DURABLE_QUEUE);
Assert.fail("should throw exception here");
} catch (ActiveMQException e) {
// ignore
}
// CREATE_NON_DURABLE_QUEUE
try {
session.createQueue(ADDRESS, NON_DURABLE_QUEUE, false);
Assert.fail("should throw exception here");
} catch (ActiveMQException e) {
// ignore
}
// DELETE_NON_DURABLE_QUEUE
try {
session.deleteQueue(NON_DURABLE_QUEUE);
Assert.fail("should throw exception here");
} catch (ActiveMQException e) {
// ignore
}
// PRODUCE
try {
ClientProducer producer = session.createProducer(ADDRESS);
producer.send(session.createMessage(true));
Assert.fail("should throw exception here");
} catch (ActiveMQException e) {
// ignore
}
// CONSUME
try {
ClientConsumer consumer = session.createConsumer(DURABLE_QUEUE);
Assert.fail("should throw exception here");
} catch (ActiveMQException e) {
// ignore
}
// MANAGE
try {
ClientProducer producer = session.createProducer(server.getConfiguration().getManagementAddress());
producer.send(session.createMessage(true));
Assert.fail("should throw exception here");
} catch (ActiveMQException e) {
// ignore
}
// BROWSE
try {
ClientConsumer browser = session.createConsumer(DURABLE_QUEUE, true);
Assert.fail("should throw exception here");
} catch (ActiveMQException e) {
// ignore
}
}
Aggregations