Java Code Examples for org.apache.activemq.broker.BrokerService#setPersistent()

The following examples show how to use org.apache.activemq.broker.BrokerService#setPersistent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmbeddedJMSBrokerLauncher.java    From cxf with Apache License 2.0 6 votes vote down vote up
public final void run() {
    try {
        broker = new BrokerService();
        broker.setPersistent(false);
        broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
        broker.setTmpDataDirectory(new File("./target"));
        broker.setUseJmx(false);
        if (brokerName != null) {
            broker.setBrokerName(brokerName);
        }
        broker.addConnector(brokerUrl1);
        broker.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: MessageAuthenticationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   BrokerService answer = new BrokerService();
   answer.setPersistent(false);
   answer.setMessageAuthorizationPolicy(new MessageAuthorizationPolicy() {
      @Override
      public boolean isAllowedToConsume(ConnectionContext context, Message message) {
         try {
            Object value = message.getProperty("myHeader");
            return "abc".equals(value);
         } catch (IOException e) {
            System.out.println("Caught: " + e);
            e.printStackTrace();
            return false;
         }
      }
   });
   answer.addConnector(bindAddress);
   return answer;
}
 
Example 3
Source File: MultiClientVmTestSuite.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private void startMessagingSystem()
{
    try
    {
        brokerService = new BrokerService();
        brokerService.addConnector(url+this.getApplicationPort2());
        brokerService.setPersistent(false);
        brokerService.setUseJmx(false);
        brokerService.setBrokerName("MithraTest"+this.getApplicationPort2());
        brokerService.setShutdownOnMasterFailure(false);
        brokerService.start();
    }
    catch(Exception e)
    {
       getLogger().error("Unable to start messaging broker");
       throw new RuntimeException("Exception during messaging broker startup", e);
    }
}
 
Example 4
Source File: SimpleNonPersistentQueueNetworkTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void configureBroker(BrokerService answer) throws Exception {
   answer.setPersistent(false);
   answer.setMonitorConnectionSplits(true);
   final List<PolicyEntry> policyEntries = new ArrayList<>();
   final PolicyEntry entry = new PolicyEntry();
   entry.setQueue(">");
   entry.setMemoryLimit(1024 * 1024 * 100); // Set to 1 MB
   entry.setOptimizedDispatch(true);
   entry.setProducerFlowControl(true);
   entry.setMaxPageSize(10);
   entry.setLazyDispatch(false);
   policyEntries.add(entry);

   final PolicyMap policyMap = new PolicyMap();
   policyMap.setPolicyEntries(policyEntries);
   answer.setDestinationPolicy(policyMap);
   super.configureBroker(answer);
}
 
Example 5
Source File: MessageGroupDelayedTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   BrokerService service = new BrokerService();
   service.setPersistent(false);
   service.setUseJmx(false);

   // Setup a destination policy where it takes only 1 message at a time.
   PolicyMap policyMap = new PolicyMap();
   PolicyEntry policy = new PolicyEntry();
   log.info("testing with consumersBeforeDispatchStarts=" + consumersBeforeDispatchStarts + " and timeBeforeDispatchStarts=" + timeBeforeDispatchStarts);
   policy.setConsumersBeforeDispatchStarts(consumersBeforeDispatchStarts);
   policy.setTimeBeforeDispatchStarts(timeBeforeDispatchStarts);
   policyMap.setDefaultEntry(policy);
   service.setDestinationPolicy(policyMap);

   connector = service.addConnector("tcp://localhost:0");
   return service;
}
 
Example 6
Source File: QueueOutboundBridgeReconnectTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected BrokerService createFirstBroker() throws Exception {
   BrokerService broker = new BrokerService();
   broker.setBrokerName("broker1");
   broker.setPersistent(false);
   broker.setUseJmx(false);
   broker.addConnector("tcp://localhost:61616");
   broker.addConnector("vm://broker1");

   SimpleJmsQueueConnector jmsQueueConnector = new SimpleJmsQueueConnector();
   jmsQueueConnector.setOutboundQueueBridges(new OutboundQueueBridge[]{new OutboundQueueBridge("RECONNECT.TEST.QUEUE")});
   jmsQueueConnector.setOutboundQueueConnectionFactory(new ActiveMQConnectionFactory("tcp://localhost:61617"));

   broker.setJmsBridgeConnectors(new JmsConnector[]{jmsQueueConnector});

   return broker;
}
 
Example 7
Source File: SimulatorJmsIT.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnProperty(name = "simulator.mode", havingValue = "embedded")
public BrokerService messageBroker() throws Exception {
    BrokerService brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.addConnector("tcp://localhost:61616");
    return brokerService;
}
 
Example 8
Source File: AMQStackOverFlowTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private BrokerService createBrokerService(final String brokerName,
                                          final String uri1,
                                          final String uri2) throws Exception {
   final BrokerService brokerService = new BrokerService();

   brokerService.setBrokerName(brokerName);
   brokerService.setPersistent(false);
   brokerService.setUseJmx(true);

   final SystemUsage memoryManager = new SystemUsage();
   //memoryManager.getMemoryUsage().setLimit(10);
   brokerService.setSystemUsage(memoryManager);

   final List<PolicyEntry> policyEntries = new ArrayList<>();

   final PolicyEntry entry = new PolicyEntry();
   entry.setQueue(">");
   //entry.setMemoryLimit(1);
   policyEntries.add(entry);

   final PolicyMap policyMap = new PolicyMap();
   policyMap.setPolicyEntries(policyEntries);
   brokerService.setDestinationPolicy(policyMap);

   final TransportConnector tConnector = new TransportConnector();
   tConnector.setUri(new URI(uri1));
   tConnector.setName(brokerName + ".transportConnector");
   brokerService.addConnector(tConnector);

   if (uri2 != null) {
      final NetworkConnector nc = new DiscoveryNetworkConnector(new URI("static:" + uri2));
      nc.setBridgeTempDestinations(true);
      nc.setBrokerName(brokerName);
      //nc.setPrefetchSize(1);
      brokerService.addNetworkConnector(nc);
   }

   return brokerService;
}
 
Example 9
Source File: SimpleNetworkTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void configureProducerBroker(BrokerService answer, String uri) throws Exception {
   configureBroker(answer);
   answer.setBrokerName(PRODUCER_BROKER_NAME);
   answer.setMonitorConnectionSplits(false);
   //answer.setSplitSystemUsageForProducersConsumers(true);
   answer.setPersistent(false);
   answer.setDeleteAllMessagesOnStartup(true);
   NetworkConnector connector = answer.addNetworkConnector("static://" + consumerBindAddress);
   //connector.setNetworkTTL(3);
   //connector.setDynamicOnly(true);
   connector.setDuplex(true);
   answer.addConnector(uri);
   answer.setUseShutdownHook(false);
}
 
Example 10
Source File: mKahaDbQueueMasterSlaveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void createSlave() throws Exception {
   // use a separate thread as the slave will block waiting for
   // the exclusive db lock
   Thread t = new Thread() {
      @Override
      public void run() {
         try {
            BrokerService broker = new BrokerService();
            broker.setBrokerName("slave");
            TransportConnector connector = new TransportConnector();
            connector.setUri(new URI(SLAVE_URL));
            broker.addConnector(connector);
            // no need for broker.setMasterConnectorURI(masterConnectorURI)
            // as the db lock provides the slave/master initialisation
            broker.setUseJmx(false);
            broker.setPersistent(true);

            MultiKahaDBPersistenceAdapter mKahaDB = new MultiKahaDBPersistenceAdapter();
            List<FilteredKahaDBPersistenceAdapter> adapters = new LinkedList<>();
            FilteredKahaDBPersistenceAdapter defaultEntry = new FilteredKahaDBPersistenceAdapter();
            defaultEntry.setPersistenceAdapter(new KahaDBPersistenceAdapter());
            defaultEntry.setPerDestination(true);
            adapters.add(defaultEntry);

            mKahaDB.setFilteredPersistenceAdapters(adapters);
            broker.setPersistenceAdapter(mKahaDB);
            broker.start();
            slave.set(broker);
            slaveStarted.countDown();
         } catch (IllegalStateException expectedOnShutdown) {
         } catch (Exception e) {
            fail("failed to start slave broker, reason:" + e);
         }
      }
   };
   t.start();
}
 
Example 11
Source File: ObjectMessageNotSerializableTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private BrokerService createBroker() throws Exception {
   BrokerService broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(false);
   broker.addConnector("tcp://localhost:0");

   broker.start();
   broker.waitUntilStarted();
   return broker;
}
 
Example 12
Source File: JDBCQueueMasterSlaveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void createSlave() throws Exception {
   // use a separate thread as the slave will block waiting for
   // the exclusive db lock
   Thread t = new Thread() {
      @Override
      public void run() {
         try {
            BrokerService broker = new BrokerService();
            broker.setBrokerName("slave");
            TransportConnector connector = new TransportConnector();
            connector.setUri(new URI(SLAVE_URL));
            broker.addConnector(connector);
            // no need for broker.setMasterConnectorURI(masterConnectorURI)
            // as the db lock provides the slave/master initialisation
            broker.setUseJmx(false);
            broker.setPersistent(true);
            JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
            persistenceAdapter.setDataSource(getExistingDataSource());
            persistenceAdapter.setCreateTablesOnStartup(false);
            broker.setPersistenceAdapter(persistenceAdapter);
            configureJdbcPersistenceAdapter(persistenceAdapter);
            configureBroker(broker);
            broker.start();
            slave.set(broker);
            slaveStarted.countDown();
         } catch (IllegalStateException expectedOnShutdown) {
         } catch (Exception e) {
            fail("failed to start slave broker, reason:" + e);
         }
      }
   };
   t.start();
}
 
Example 13
Source File: SimpleJmsListenerContainerFactoryExampleTest.java    From amqp-10-jms-spring-boot with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    brokerService = new BrokerService();

    brokerService.addConnector("amqp://localhost:5672");
    brokerService.setPersistent(false);
    brokerService.getManagementContext().setCreateConnector(false);

    brokerService.start();
    brokerService.waitUntilStarted();
}
 
Example 14
Source File: SchedulerDBVersionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker(JobSchedulerStoreImpl scheduler) throws Exception {
   BrokerService answer = new BrokerService();
   answer.setJobSchedulerStore(scheduler);
   answer.setPersistent(true);
   answer.setDataDirectory("target");
   answer.setSchedulerSupport(true);
   answer.setUseJmx(false);
   return answer;
}
 
Example 15
Source File: ExceptionListenerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Before
public void startBroker() throws Exception {
   brokerService = new BrokerService();
   brokerService.setAdvisorySupport(false);
   brokerService.setUseJmx(false);
   brokerService.setPersistent(false);
   brokerService.setPlugins(new BrokerPlugin[]{new SimpleAuthenticationPlugin(new ArrayList())});
   brokerUri = brokerService.addConnector("tcp://0.0.0.0:0").getConnectUri();
   brokerService.start();
}
 
Example 16
Source File: OpenTypeSupportTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
   brokerService = new BrokerService();
   brokerService.setPersistent(false);
   brokerService.setUseJmx(true);
   connectionUri = brokerService.addConnector(BROKER_ADDRESS).getPublishableConnectString();
   brokerService.start();
   connectionFactory = new ActiveMQConnectionFactory(connectionUri);
   sendMessage();
}
 
Example 17
Source File: ConsumeJMSIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * <p>
 * This test validates the connection resources are closed if the publisher is marked as invalid.
 * </p>
 * <p>
 * This tests validates the proper resources handling for TCP connections using ActiveMQ (the bug was discovered against ActiveMQ 5.x). In this test, using some ActiveMQ's classes is possible to
 * verify if an opened socket is closed. See <a href="https://issues.apache.org/jira/browse/NIFI-7034">NIFI-7034</a>.
 * </p>
 * @throws Exception
 *             any error related to the broker.
 */
@Test(timeout = 10000)
public void validateNIFI7034() throws Exception {
    class ConsumeJMSForNifi7034 extends ConsumeJMS {
        @Override
        protected void rendezvousWithJms(ProcessContext context, ProcessSession processSession, JMSConsumer consumer) throws ProcessException {
            super.rendezvousWithJms(context, processSession, consumer);
            consumer.setValid(false);
        }
    }
    BrokerService broker = new BrokerService();
    try {
        broker.setPersistent(false);
        broker.setBrokerName("nifi7034publisher");
        TransportConnector connector = broker.addConnector("tcp://127.0.0.1:0");
        int port = connector.getServer().getSocketAddress().getPort();
        broker.start();

        ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("validateNIFI7034://127.0.0.1:" + port);
        final String destinationName = "nifi7034";
        final AtomicReference<TcpTransport> tcpTransport = new AtomicReference<TcpTransport>();
        TcpTransportFactory.registerTransportFactory("validateNIFI7034", new TcpTransportFactory() {
            @Override
            protected TcpTransport createTcpTransport(WireFormat wf, SocketFactory socketFactory, URI location, URI localLocation) throws UnknownHostException, IOException {
                TcpTransport transport = super.createTcpTransport(wf, socketFactory, location, localLocation);
                tcpTransport.set(transport);
                return transport;
            }
        });

        TestRunner runner = TestRunners.newTestRunner(new ConsumeJMSForNifi7034());
        JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
        when(cs.getIdentifier()).thenReturn("cfProvider");
        when(cs.getConnectionFactory()).thenReturn(cf);
        runner.addControllerService("cfProvider", cs);
        runner.enableControllerService(cs);

        runner.setProperty(ConsumeJMS.CF_SERVICE, "cfProvider");
        runner.setProperty(ConsumeJMS.DESTINATION, destinationName);
        runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.TOPIC);

        try {
            runner.run();
            fail("Unit test implemented in a way this line must not be called");
        } catch (AssertionError e) {
            assertFalse("It is expected transport be closed. ", tcpTransport.get().isConnected());
        }
    } finally {
        if (broker != null) {
            broker.stop();
        }
    }
}
 
Example 18
Source File: NIOJmsSendAndReceiveTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected BrokerService createBroker() throws Exception {
   BrokerService answer = new BrokerService();
   answer.setPersistent(false);
   answer.addConnector(getBrokerURL());
   return answer;
}
 
Example 19
Source File: BrokerExtension.java    From james-project with Apache License 2.0 4 votes vote down vote up
public BrokerExtension() throws Exception  {
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.setUseJmx(false);
    broker.addConnector("tcp://127.0.0.1:61616");
}
 
Example 20
Source File: MemoryAllocationTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected void configureBroker(BrokerService answer) throws Exception {
   answer.setPersistent(false);
   answer.addConnector(bindAddress);
   answer.setDeleteAllMessagesOnStartup(true);
}