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

The following examples show how to use org.apache.activemq.broker.BrokerService#addConnector() . 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: MQTTStreamSourceTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Before
public void startBroker() throws Exception {
  port = findFreePort();
  brokerService = new BrokerService();
  brokerService.setDeleteAllMessagesOnStartup( true );
  brokerService.setPersistent( false );
  brokerService.addConnector( "mqtt://localhost:" + port );
  brokerService.start();
  brokerService.waitUntilStarted();
  when( consumerMeta.getQos() ).thenReturn( "2" );
  when( consumerMeta.withVariables( any() ) ).thenReturn( consumerMeta );
  when( consumerMeta.getMqttServer() ).thenReturn( "127.0.0.1:" + port );
  when( consumerMeta.getTopics() ).thenReturn( singletonList( "mytopic" ) );
  when( mqttConsumer.environmentSubstitute( anyString() ) )
    .thenAnswer( answer -> answer.getArguments()[ 0 ] );
  when( mqttConsumer.environmentSubstitute( any( String[].class ) ) )
    .thenAnswer( answer -> answer.getArguments()[ 0 ] );
  when( mqttConsumer.getLogChannel() ).thenReturn( logger );
  when( mqttConsumer.getStepMeta() ).thenReturn( stepMeta );
  when( stepMeta.getName() ).thenReturn( "Mqtt Step" );
  when( mqttConsumer.getVariablizedStepMeta() ).thenReturn( consumerMeta );
  when( subtransExecutor.getPrefetchCount() ).thenReturn( 1000 );
  when( mqttConsumer.getSubtransExecutor() ).thenReturn( subtransExecutor );
}
 
Example 2
Source File: NonBlockingConsumerRedeliveryTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Before
public void startBroker() throws Exception {
   broker = new BrokerService();
   broker.setDeleteAllMessagesOnStartup(true);
   broker.setPersistent(false);
   broker.setUseJmx(false);
   broker.addConnector("tcp://0.0.0.0:0");
   broker.start();
   broker.waitUntilStarted();

   connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
   connectionFactory = new ActiveMQConnectionFactory(connectionUri);
   connectionFactory.setNonBlockingRedelivery(true);

   RedeliveryPolicy policy = connectionFactory.getRedeliveryPolicy();
   policy.setInitialRedeliveryDelay(TimeUnit.SECONDS.toMillis(2));
   policy.setBackOffMultiplier(-1);
   policy.setRedeliveryDelay(TimeUnit.SECONDS.toMillis(2));
   policy.setMaximumRedeliveryDelay(-1);
   policy.setUseExponentialBackOff(false);
   policy.setMaximumRedeliveries(-1);
}
 
Example 3
Source File: InactiveDurableTopicTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
   super.setUp();
   broker = new BrokerService();

   //broker.setPersistenceAdapter(new KahaPersistenceAdapter());
     /*
      * JournalPersistenceAdapterFactory factory = new
      * JournalPersistenceAdapterFactory();
      * factory.setDataDirectoryFile(broker.getDataDirectory());
      * factory.setTaskRunnerFactory(broker.getTaskRunnerFactory());
      * factory.setUseJournal(false); broker.setPersistenceFactory(factory);
      */
   broker.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
   broker.start();
   connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_URL);
     /*
      * Doesn't matter if you enable or disable these, so just leaving them
      * out for this test case connectionFactory.setAlwaysSessionAsync(true);
      * connectionFactory.setAsyncDispatch(true);
      */
   connectionFactory.setUseAsyncSend(true);
}
 
Example 4
Source File: BrokerServer.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void init(final Properties properties) throws Exception {
    final String port = properties.getProperty("port", "1527");
    final String bind = properties.getProperty("bind");
    final String disabled = properties.getProperty("disabled");
    this.port = Integer.parseInt(port);
    this.disabled = Boolean.parseBoolean(disabled);
    host = InetAddress.getByName(bind);

    if (this.disabled) {
        return;
    }
    final URI uri = new URI("tcp", null, bind, this.port, null, null, null);

    broker = new BrokerService();
    broker.setPersistent(false);
    broker.addConnector(uri);
}
 
Example 5
Source File: ActiveMQConnectionFactoryTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void assertCreateConnection(String uri) throws Exception {
   // Start up a broker with a tcp connector.
   broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(false);
   TransportConnector connector = broker.addConnector(uri);
   broker.start();

   URI temp = new URI(uri);
   // URI connectURI = connector.getServer().getConnectURI();
   // TODO this sometimes fails when using the actual local host name
   URI currentURI = new URI(connector.getPublishableConnectString());

   // sometimes the actual host name doesn't work in this test case
   // e.g. on OS X so lets use the original details but just use the actual
   // port
   URI connectURI = new URI(temp.getScheme(), temp.getUserInfo(), temp.getHost(), currentURI.getPort(), temp.getPath(), temp.getQuery(), temp.getFragment());

   LOG.info("connection URI is: " + connectURI);

   // This should create the connection.
   ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(connectURI);
   connection = (ActiveMQConnection) cf.createConnection();
   assertNotNull(connection);
}
 
Example 6
Source File: JmsWSConnectionTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setDeleteAllMessagesOnStartup(true);
    brokerService.setUseJmx(false);

    TransportConnector connector = brokerService.addConnector(
            "ws://0.0.0.0:" + getProxyPort() + "?websocket.maxBinaryMessageSize=1048576");
    connectionURI = connector.getPublishableConnectURI();
    LOG.debug("Using amqp+ws connection: {}", connectionURI);

    brokerService.start();
    brokerService.waitUntilStarted();
}
 
Example 7
Source File: JMSBrokerController.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public boolean startProcess() {
    try {
        //using embedded jms broker
        broker = new BrokerService();
        // configure the broker
        broker.setBrokerName("inboundSampleBroker");
        broker.addConnector(providerURL);
        broker.setPersistent(true);
        broker.start();
        log.info("JMSBrokerController: ActiveMQ Broker is Successfully started. continuing tests");
        return true;
    } catch (Exception e) {
        log.error("There was an error starting JMS broker for providerURL : " + providerURL, e);
        return false;
    }
}
 
Example 8
Source File: MultiVmNotificationsTestSuite.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 9
Source File: QueueBridgeStandaloneReconnectTest.java    From activemq-artemis with Apache License 2.0 5 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");

   return broker;
}
 
Example 10
Source File: EmbeddedBroker.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BrokerService broker = new BrokerService();
    broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
    broker.setDataDirectory("target/activemq-data");
    broker.addConnector("tcp://localhost:61616");
    broker.start();
    System.out.println("JMS broker ready ...");
    Thread.sleep(125 * 60 * 1000);
    System.out.println("JMS broker exiting");
    broker.stop();
    System.exit(0);
}
 
Example 11
Source File: MessageGroupLateArrivalsTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker() throws Exception {
   BrokerService service = new BrokerService();
   service.setPersistent(false);
   service.setUseJmx(false);

   PolicyMap policyMap = new PolicyMap();
   PolicyEntry policy = new PolicyEntry();
   policy.setUseConsumerPriority(true);
   policyMap.setDefaultEntry(policy);
   service.setDestinationPolicy(policyMap);

   connector = service.addConnector("tcp://localhost:0");
   return service;
}
 
Example 12
Source File: QueueBridgeStandaloneReconnectTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createSecondBroker() throws Exception {

      BrokerService broker = new BrokerService();
      broker.setBrokerName("broker2");
      broker.setPersistent(false);
      broker.setUseJmx(false);
      broker.addConnector("tcp://localhost:61617");

      return broker;
   }
 
Example 13
Source File: JmsWSSConnectionTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setDeleteAllMessagesOnStartup(true);
    brokerService.setUseJmx(false);

    // Setup broker SSL context...
    TransportOptions sslOptions = new TransportOptions();
    sslOptions.setKeyStoreLocation(KEYSTORE);
    sslOptions.setKeyStorePassword(PASSWORD);
    sslOptions.setVerifyHost(false);

    SSLContext sslContext = TransportSupport.createJdkSslContext(sslOptions);

    final SslContext brokerContext = new SslContext();
    brokerContext.setSSLContext(sslContext);

    brokerService.setSslContext(brokerContext);

    TransportConnector connector = brokerService.addConnector("wss://0.0.0.0:" + getProxyPort());
    connectionURI = connector.getPublishableConnectURI();
    LOG.debug("Using amqp+wss connection: {}", connectionURI);

    brokerService.start();
    brokerService.waitUntilStarted();

    connectionURI = connector.getPublishableConnectURI();
}
 
Example 14
Source File: ProxyFailoverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void startRemoteBroker(boolean delete) throws Exception {
   remoteBroker = new BrokerService();
   remoteBroker.addConnector("tcp://localhost:61616");
   if (delete) {
      remoteBroker.deleteAllMessages();
   }
   remoteBroker.setUseJmx(false);
   remoteBroker.start();
   remoteBroker.waitUntilStarted();
}
 
Example 15
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 16
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 17
Source File: TraceBrokerPathPluginTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   TraceBrokerPathPlugin tbppA = new TraceBrokerPathPlugin();
   tbppA.setStampProperty(traceProperty);

   TraceBrokerPathPlugin tbppB = new TraceBrokerPathPlugin();
   tbppB.setStampProperty(traceProperty);

   brokerA = new BrokerService();
   brokerA.setBrokerName("brokerA");
   brokerA.setPersistent(false);
   brokerA.setUseJmx(true);
   brokerA.setPlugins(new BrokerPlugin[]{tbppA});
   tcpConnectorA = brokerA.addConnector("tcp://localhost:0");

   brokerB = new BrokerService();
   brokerB.setBrokerName("brokerB");
   brokerB.setPersistent(false);
   brokerB.setUseJmx(true);
   brokerB.setPlugins(new BrokerPlugin[]{tbppB});
   tcpConnectorB = brokerB.addConnector("tcp://localhost:0");

   brokerA.addNetworkConnector("static:(" + tcpConnectorB.getConnectUri().toString() + ")");

   brokerB.start();
   brokerB.waitUntilStarted();
   brokerA.start();
   brokerA.waitUntilStarted();

   // Initialise connection to A and MessageProducer
   connectionA = new ActiveMQConnectionFactory(tcpConnectorA.getConnectUri()).createConnection();
   connectionA.start();
   sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE);
   producer = sessionA.createProducer(sessionA.createQueue(queue));
   producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

   // Initialise connection to B and MessageConsumer
   connectionB = new ActiveMQConnectionFactory(tcpConnectorB.getConnectUri()).createConnection();
   connectionB.start();
   sessionB = connectionB.createSession(false, Session.AUTO_ACKNOWLEDGE);
   consumer = sessionB.createConsumer(sessionB.createQueue(queue));

}
 
Example 18
Source File: PublishJMSIT.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="NIFI-7034">https://issues.apache.org/jira/browse/NIFI-7034</a>.
 * </p>
 * @throws Exception any error related to the broker.
 */
@Test(timeout = 10000)
public void validateNIFI7034() throws Exception {
    class PublishJmsForNifi7034 extends PublishJMS {
        @Override
        protected void rendezvousWithJms(ProcessContext context, ProcessSession processSession, JMSPublisher publisher) throws ProcessException {
            super.rendezvousWithJms(context, processSession, publisher);
            publisher.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 PublishJmsForNifi7034());
        JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
        when(cs.getIdentifier()).thenReturn("cfProvider");
        when(cs.getConnectionFactory()).thenReturn(cf);
        runner.addControllerService("cfProvider", cs);
        runner.enableControllerService(cs);

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

        runner.enqueue("hi".getBytes());
        runner.run();
        assertFalse("It is expected transport be closed. ", tcpTransport.get().isConnected());
    } finally {
        if (broker != null) {
            broker.stop();
        }
    }
}
 
Example 19
Source File: SimpleTopicTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected void configureBroker(BrokerService answer, String uri) throws Exception {
   answer.setDeleteAllMessagesOnStartup(true);
   answer.addConnector(uri);
   answer.setUseShutdownHook(false);
}
 
Example 20
Source File: LevelDBStoreQueueTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@Override
protected void configureBroker(BrokerService answer, String uri) throws Exception {

   File dataFileDir = new File("target/test-amq-data/perfTest/amq");

   LevelDBStore adaptor = new LevelDBStore();
   adaptor.setDirectory(dataFileDir);

   answer.setPersistenceAdapter(adaptor);
   answer.addConnector(uri);
   answer.setDeleteAllMessagesOnStartup(true);

}