use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.
the class JournalPendingMessageTest method getQueues.
protected List<Queue> getQueues(final String address) throws Exception {
final List<Queue> queues = new ArrayList<>();
for (Binding binding : server.getPostOffice().getDirectBindings(SimpleString.toSimpleString(address)).getBindings()) {
if (binding.getType() == BindingType.LOCAL_QUEUE) {
LocalQueueBinding queueBinding = (LocalQueueBinding) binding;
queues.add(queueBinding.getQueue());
}
}
return queues;
}
use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method closeConsumerConnectionsForAddress.
@Override
public boolean closeConsumerConnectionsForAddress(final String address) {
boolean closed = false;
checkStarted();
clearIO();
try {
for (Binding binding : postOffice.getMatchingBindings(SimpleString.toSimpleString(address)).getBindings()) {
if (binding instanceof LocalQueueBinding) {
Queue queue = ((LocalQueueBinding) binding).getQueue();
for (Consumer consumer : queue.getConsumers()) {
if (consumer instanceof ServerConsumer) {
ServerConsumer serverConsumer = (ServerConsumer) consumer;
RemotingConnection connection = null;
for (RemotingConnection potentialConnection : remotingService.getConnections()) {
if (potentialConnection.getID().toString().equals(serverConsumer.getConnectionID())) {
connection = potentialConnection;
}
}
if (connection != null) {
remotingService.removeConnection(connection.getID());
connection.fail(ActiveMQMessageBundle.BUNDLE.consumerConnectionsClosedByManagement(address));
closed = true;
}
}
}
}
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToCloseConsumerConnectionsForAddress(address, e);
} finally {
blockOnIO();
}
return closed;
}
use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.
the class QueueImplTest method testTotalIteratorOrder.
@Test
public void testTotalIteratorOrder() throws Exception {
final String MY_ADDRESS = "myAddress";
final String MY_QUEUE = "myQueue";
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig(), true));
AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
server.getAddressSettingsRepository().addMatch("#", defaultSetting);
server.start();
ServerLocator locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
ClientSessionFactory factory = createSessionFactory(locator);
ClientSession session = addClientSession(factory.createSession(false, true, true));
session.createQueue(MY_ADDRESS, MY_QUEUE, true);
ClientProducer producer = addClientProducer(session.createProducer(MY_ADDRESS));
for (int i = 0; i < 50; i++) {
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeBytes(new byte[1024]);
message.putIntProperty("order", i);
producer.send(message);
}
producer.close();
session.close();
factory.close();
locator.close();
Queue queue = ((LocalQueueBinding) server.getPostOffice().getBinding(new SimpleString(MY_QUEUE))).getQueue();
LinkedListIterator<MessageReference> totalIterator = queue.browserIterator();
try {
int i = 0;
while (totalIterator.hasNext()) {
MessageReference ref = totalIterator.next();
Assert.assertEquals(i++, ref.getMessage().getIntProperty("order").intValue());
}
} finally {
totalIterator.close();
server.stop();
}
}
use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.
the class ActiveMQMessageHandlerSecurityTest method testSimpleMessageReceivedOnQueueWithSecuritySucceeds.
@Test
public void testSimpleMessageReceivedOnQueueWithSecuritySucceeds() throws Exception {
ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
securityManager.getConfiguration().addUser("testuser", "testpassword");
securityManager.getConfiguration().addRole("testuser", "arole");
Role role = new Role("arole", false, true, false, false, false, false, false, false, false, false);
Set<Role> roles = new HashSet<>();
roles.add(role);
server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
MyBootstrapContext ctx = new MyBootstrapContext();
qResourceAdapter.start(ctx);
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setResourceAdapter(qResourceAdapter);
spec.setUseJNDI(false);
spec.setDestinationType("javax.jms.Queue");
spec.setDestination(MDBQUEUE);
spec.setUser("testuser");
spec.setPassword("testpassword");
spec.setSetupAttempts(0);
qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
CountDownLatch latch = new CountDownLatch(1);
DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
qResourceAdapter.endpointActivation(endpointFactory, spec);
Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 15);
qResourceAdapter.endpointDeactivation(endpointFactory, spec);
qResourceAdapter.stop();
}
use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.
the class ActiveMQServerTestCase method assertRemainingMessages.
protected boolean assertRemainingMessages(final int expected) throws Exception {
String queueName = "Queue1";
Binding binding = servers.get(0).getActiveMQServer().getPostOffice().getBinding(SimpleString.toSimpleString(queueName));
if (binding != null && binding instanceof LocalQueueBinding) {
((LocalQueueBinding) binding).getQueue().flushExecutor();
}
Long messageCount = null;
for (int i = 0; i < 10; i++) {
messageCount = servers.get(0).getMessageCountForQueue(queueName);
if (messageCount.longValue() == expected) {
break;
} else {
Thread.sleep(100);
}
}
ProxyAssertSupport.assertEquals(expected, messageCount.intValue());
return expected == messageCount.intValue();
}
Aggregations