Search in sources :

Example 66 with BrokerService

use of org.apache.activemq.broker.BrokerService in project activemq-artemis by apache.

the class RequestReplyNoAdvisoryNetworkTest method doTestNonAdvisoryNetworkRequestReply.

public void doTestNonAdvisoryNetworkRequestReply() throws Exception {
    waitForBridgeFormation(a, 1, 0);
    waitForBridgeFormation(b, 1, 0);
    ActiveMQConnectionFactory sendFactory = createConnectionFactory(a);
    ActiveMQConnection sendConnection = createConnection(sendFactory);
    ActiveMQSession sendSession = (ActiveMQSession) sendConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = sendSession.createProducer(sendQ);
    ActiveMQTempQueue realReplyQ = (ActiveMQTempQueue) sendSession.createTemporaryQueue();
    TextMessage message = sendSession.createTextMessage("1");
    message.setJMSReplyTo(realReplyQ);
    producer.send(message);
    LOG.info("request sent");
    // responder
    ActiveMQConnectionFactory consumerFactory = createConnectionFactory(b);
    ActiveMQConnection consumerConnection = createConnection(consumerFactory);
    ActiveMQSession consumerSession = (ActiveMQSession) consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = consumerSession.createConsumer(sendQ);
    TextMessage received = (TextMessage) consumer.receive(receiveTimeout);
    assertNotNull("got request from sender ok", received);
    LOG.info("got request, sending reply");
    MessageProducer consumerProducer = consumerSession.createProducer(received.getJMSReplyTo());
    consumerProducer.send(consumerSession.createTextMessage("got " + received.getText()));
    // temp dest on reply broker tied to this connection, setOptimizedDispatch=true ensures
    // message gets delivered before destination is removed
    consumerConnection.close();
    // reply consumer
    MessageConsumer replyConsumer = sendSession.createConsumer(realReplyQ);
    TextMessage reply = (TextMessage) replyConsumer.receive(receiveTimeout);
    assertNotNull("expected reply message", reply);
    assertEquals("text is as expected", "got 1", reply.getText());
    sendConnection.close();
    LOG.info("checking for dangling temp destinations");
    // ensure all temp dests get cleaned up on all brokers
    for (BrokerService brokerService : brokers) {
        final RegionBroker regionBroker = (RegionBroker) brokerService.getRegionBroker();
        assertTrue("all temps are gone on " + regionBroker.getBrokerName(), Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                Map<?, ?> tempTopics = regionBroker.getTempTopicRegion().getDestinationMap();
                LOG.info("temp topics on " + regionBroker.getBrokerName() + ", " + tempTopics);
                Map<?, ?> tempQ = regionBroker.getTempQueueRegion().getDestinationMap();
                LOG.info("temp queues on " + regionBroker.getBrokerName() + ", " + tempQ);
                return tempQ.isEmpty() && tempTopics.isEmpty();
            }
        }));
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) ActiveMQSession(org.apache.activemq.ActiveMQSession) RegionBroker(org.apache.activemq.broker.region.RegionBroker) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) MessageProducer(javax.jms.MessageProducer) BrokerService(org.apache.activemq.broker.BrokerService) ActiveMQTempQueue(org.apache.activemq.command.ActiveMQTempQueue) TextMessage(javax.jms.TextMessage)

Example 67 with BrokerService

use of org.apache.activemq.broker.BrokerService in project activemq-artemis by apache.

the class TwoBrokerVirtualTopicForwardingTest method createAndConfigureBroker.

private BrokerService createAndConfigureBroker(URI uri) throws Exception {
    BrokerService broker = createBroker(uri);
    configurePersistenceAdapter(broker);
    return broker;
}
Also used : BrokerService(org.apache.activemq.broker.BrokerService)

Example 68 with BrokerService

use of org.apache.activemq.broker.BrokerService in project activemq-artemis by apache.

the class TwoBrokerTopicSendReceiveTest method tearDown.

@Override
protected void tearDown() throws Exception {
    super.tearDown();
    for (Iterator<BrokerService> iter = brokers.values().iterator(); iter.hasNext(); ) {
        BrokerService broker = iter.next();
        ServiceSupport.dispose(broker);
        iter.remove();
    }
}
Also used : BrokerService(org.apache.activemq.broker.BrokerService)

Example 69 with BrokerService

use of org.apache.activemq.broker.BrokerService in project activemq-artemis by apache.

the class TwoBrokerTopicSendReceiveUsingJavaConfigurationTest method createReceiverConnectionFactory.

@Override
protected ActiveMQConnectionFactory createReceiverConnectionFactory() throws JMSException {
    try {
        receiveBroker = new BrokerService();
        receiveBroker.setBrokerName("receiveBroker");
        receiveBroker.setUseJmx(false);
        receiveBroker.setPersistent(false);
        receiveBroker.addConnector("tcp://localhost:62002");
        receiveBroker.addNetworkConnector("static:failover:tcp://localhost:62001");
        receiveBroker.start();
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:62002");
        return factory;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) BrokerService(org.apache.activemq.broker.BrokerService) JMSException(javax.jms.JMSException)

Example 70 with BrokerService

use of org.apache.activemq.broker.BrokerService in project activemq-artemis by apache.

the class TwoBrokerVirtualDestDinamicallyIncludedDestTest method createAndConfigureBroker.

private BrokerService createAndConfigureBroker(URI uri) throws Exception {
    BrokerService broker = createBroker(uri);
    configurePersistenceAdapter(broker);
    // make all topics virtual and consumers use the default prefix
    VirtualDestinationInterceptor virtualDestinationInterceptor = new VirtualDestinationInterceptor();
    VirtualTopic vTopic = new VirtualTopic();
    vTopic.setLocal(true);
    virtualDestinationInterceptor.setVirtualDestinations(new VirtualDestination[] { vTopic });
    DestinationInterceptor[] destinationInterceptors = new DestinationInterceptor[] { virtualDestinationInterceptor };
    broker.setDestinationInterceptors(destinationInterceptors);
    return broker;
}
Also used : VirtualTopic(org.apache.activemq.broker.region.virtual.VirtualTopic) DestinationInterceptor(org.apache.activemq.broker.region.DestinationInterceptor) VirtualDestinationInterceptor(org.apache.activemq.broker.region.virtual.VirtualDestinationInterceptor) BrokerService(org.apache.activemq.broker.BrokerService) VirtualDestinationInterceptor(org.apache.activemq.broker.region.virtual.VirtualDestinationInterceptor)

Aggregations

BrokerService (org.apache.activemq.broker.BrokerService)349 URI (java.net.URI)53 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)45 PolicyMap (org.apache.activemq.broker.region.policy.PolicyMap)45 Test (org.junit.Test)43 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)32 TransportConnector (org.apache.activemq.broker.TransportConnector)31 Before (org.junit.Before)22 File (java.io.File)20 MemoryPersistenceAdapter (org.apache.activemq.store.memory.MemoryPersistenceAdapter)17 JMSException (javax.jms.JMSException)16 JDBCPersistenceAdapter (org.apache.activemq.store.jdbc.JDBCPersistenceAdapter)14 KahaDBPersistenceAdapter (org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)14 BrokerFactoryBean (org.apache.activemq.xbean.BrokerFactoryBean)14 NetworkConnector (org.apache.activemq.network.NetworkConnector)13 MessageConsumer (javax.jms.MessageConsumer)12 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)12 ArrayList (java.util.ArrayList)11 Destination (javax.jms.Destination)11 ClassPathResource (org.springframework.core.io.ClassPathResource)10