use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class TwoBrokerVirtualTopicForwardingTest method dontBridgeVirtualTopicConsumerQueues.
private void dontBridgeVirtualTopicConsumerQueues(String local, String remote) throws Exception {
NetworkConnector bridge = bridgeBrokers(local, remote);
bridge.setDecreaseNetworkConsumerPriority(true);
LinkedList<ActiveMQDestination> excludedDestinations = new LinkedList<>();
excludedDestinations.add(new ActiveMQQueue("Consumer.*.VirtualTopic.>"));
bridge.setExcludedDestinations(excludedDestinations);
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class TwoBrokerQueueClientsReconnectTest method testDuplicateSendWithNoAuditEnqueueCountStat.
public void testDuplicateSendWithNoAuditEnqueueCountStat() throws Exception {
broker1 = "BrokerA";
broker2 = "BrokerB";
NetworkConnector networkConnector = bridgeBrokers(broker1, broker2);
final AtomicBoolean first = new AtomicBoolean();
final CountDownLatch gotMessageLatch = new CountDownLatch(1);
BrokerService brokerService = brokers.get(broker2).broker;
brokerService.setPersistent(true);
brokerService.setDeleteAllMessagesOnStartup(true);
// disable concurrent dispatch otherwise store duplicate suppression will be skipped b/c cursor audit is already
// disabled so verification of stats will fail - ie: duplicate will be dispatched
((KahaDBPersistenceAdapter) brokerService.getPersistenceAdapter()).setConcurrentStoreAndDispatchQueues(false);
brokerService.setPlugins(new BrokerPlugin[] { new BrokerPluginSupport() {
@Override
public void send(final ProducerBrokerExchange producerExchange, org.apache.activemq.command.Message messageSend) throws Exception {
super.send(producerExchange, messageSend);
if (first.compareAndSet(false, true)) {
producerExchange.getConnectionContext().setDontSendReponse(true);
new Thread() {
@Override
public void run() {
try {
LOG.info("Waiting for recepit");
assertTrue("message received on time", gotMessageLatch.await(60, TimeUnit.SECONDS));
LOG.info("Stopping connection post send and receive and multiple producers");
producerExchange.getConnectionContext().getConnection().stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
}
} });
// Create queue
ActiveMQDestination dest = createDestination("TEST.FOO", false);
// statically include our destination
networkConnector.addStaticallyIncludedDestination(dest);
// Run brokers
startAllBrokers();
waitForBridgeFormation();
sendMessages("BrokerA", dest, 1);
// wait for broker2 to get the initial forward
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return brokers.get(broker2).broker.getAdminView().getTotalMessageCount() == 1;
}
});
// message still pending on broker1
assertEquals("messages message still there", 1, brokers.get(broker1).broker.getAdminView().getTotalMessageCount());
// allow the bridge to be shutdown and restarted
gotMessageLatch.countDown();
// verify message is forwarded after restart
assertTrue("no messages enqueued on origin", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 0 == brokers.get(broker1).broker.getAdminView().getTotalMessageCount();
}
}));
assertEquals("one messages pending", 1, brokers.get(broker2).broker.getAdminView().getTotalMessageCount());
assertEquals("one messages enqueued", 1, brokers.get(broker2).broker.getDestination(dest).getDestinationStatistics().getEnqueues().getCount());
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class NoDuplicateOnTopicNetworkTest method testProducerConsumerTopic.
public void testProducerConsumerTopic() throws Exception {
final CountDownLatch consumerStarted = new CountDownLatch(1);
Thread producerThread = new Thread(new Runnable() {
@Override
public void run() {
TopicWithDuplicateMessages producer = new TopicWithDuplicateMessages();
producer.setBrokerURL(BROKER_1);
producer.setTopicName(TOPIC_NAME);
try {
producer.produce();
} catch (JMSException e) {
fail("Unexpected " + e);
}
}
});
final TopicWithDuplicateMessages consumer = new TopicWithDuplicateMessages();
Thread consumerThread = new Thread(new Runnable() {
@Override
public void run() {
consumer.setBrokerURL(BROKER_2);
consumer.setTopicName(TOPIC_NAME);
try {
consumer.consumer();
consumerStarted.countDown();
consumer.getLatch().await(60, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Unexpected " + e);
}
}
});
consumerThread.start();
LOG.info("Started Consumer");
assertTrue("consumer started eventually", consumerStarted.await(10, TimeUnit.SECONDS));
// ensure subscription has percolated though the network
Thread.sleep(2000);
// verify network consumer priority
final RegionBroker regionBroker = (RegionBroker) broker1.getRegionBroker();
assertTrue("Found network destination with priority as expected", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
Map<ActiveMQDestination, Destination> destinationMap = regionBroker.getTopicRegion().getDestinationMap();
LOG.info("destinations: " + destinationMap.keySet());
boolean found = false;
for (Destination destination : destinationMap.values()) {
List<Subscription> subscriptions = destination.getConsumers();
LOG.info(destination + " subscriptions: " + subscriptions);
for (Subscription subscription : subscriptions) {
if (subscription.getConsumerInfo().isNetworkSubscription()) {
LOG.info("subscription: " + subscription + ", priority: " + subscription.getConsumerInfo().getPriority());
assertTrue("priority is < our base: " + subscription.getConsumerInfo().getPriority(), subscription.getConsumerInfo().getPriority() <= BASE_PRIORITY);
found = true;
}
}
}
return found;
}
}));
producerThread.start();
LOG.info("Started Producer");
producerThread.join();
consumerThread.join();
int duplicateCount = 0;
Map<String, String> map = new HashMap<>();
for (String msg : consumer.getMessageStrings()) {
if (map.containsKey(msg)) {
LOG.info("got duplicate: " + msg);
duplicateCount++;
}
map.put(msg, msg);
}
consumer.unSubscribe();
if (suppressDuplicateTopicSubs || dispatchPolicy instanceof PriorityNetworkDispatchPolicy) {
assertEquals("no duplicates", 0, duplicateCount);
assertEquals("got all required messages: " + map.size(), consumer.getNumMessages(), map.size());
} else {
assertTrue("we can get some duplicates: " + duplicateCount, duplicateCount >= 0);
if (duplicateCount == 0) {
assertEquals("got all required messages: " + map.size(), consumer.getNumMessages(), map.size());
}
}
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class NetworkDestinationFilterTest method testFilter.
public void testFilter() throws Exception {
NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
assertEquals(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX + ">", config.getDestinationFilter());
List<ActiveMQDestination> dests = new ArrayList<>();
config.setDynamicallyIncludedDestinations(dests);
assertEquals(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX + ">", config.getDestinationFilter());
dests.add(new ActiveMQQueue("TEST.>"));
dests.add(new ActiveMQTopic("TEST.>"));
dests.add(new ActiveMQTempQueue("TEST.>"));
String prefix = AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX;
assertEquals(prefix + "Queue.TEST.>," + prefix + "Topic.TEST.>", config.getDestinationFilter());
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class DiscoveryTransportBrokerTest method testPublisherFailsOver.
public void testPublisherFailsOver() throws Exception {
ActiveMQDestination destination = new ActiveMQQueue("TEST");
int deliveryMode = DeliveryMode.NON_PERSISTENT;
// Start a normal consumer on the local broker
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.request(consumerInfo1);
// Start a normal consumer on a remote broker
StubConnection connection2 = createRemoteConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo();
SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
connection2.send(connectionInfo2);
connection2.send(sessionInfo2);
connection2.request(consumerInfo2);
// Start a failover publisher.
StubConnection connection3 = createFailoverConnection();
ConnectionInfo connectionInfo3 = createConnectionInfo();
SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
connection3.send(connectionInfo3);
connection3.send(sessionInfo3);
connection3.send(producerInfo3);
// Send the message using the fail over publisher.
connection3.request(createMessage(producerInfo3, destination, deliveryMode));
// The message will be sent to one of the brokers.
FailoverTransport ft = connection3.getTransport().narrow(FailoverTransport.class);
// See which broker we were connected to.
StubConnection connectionA;
StubConnection connectionB;
TransportConnector serverA;
if (connector.getServer().getConnectURI().getPort() == ft.getConnectedTransportURI().getPort()) {
connectionA = connection1;
connectionB = connection2;
serverA = connector;
} else {
connectionA = connection2;
connectionB = connection1;
serverA = remoteConnector;
}
assertNotNull(receiveMessage(connectionA));
assertNoMessagesLeft(connectionB);
// Dispose the server so that it fails over to the other server.
LOG.info("Disconnecting active server");
serverA.stop();
LOG.info("Sending request that should failover");
connection3.request(createMessage(producerInfo3, destination, deliveryMode));
assertNotNull(receiveMessage(connectionB));
assertNoMessagesLeft(connectionA);
}
Aggregations