Java Code Examples for org.apache.activemq.broker.BrokerService#setPlugins()
The following examples show how to use
org.apache.activemq.broker.BrokerService#setPlugins() .
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: CustomConfigurationExampleTest.java From amqp-10-jms-spring-boot with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { brokerService = new BrokerService(); brokerService.addConnector("amqp://localhost:5672"); brokerService.setPersistent(false); brokerService.getManagementContext().setCreateConnector(false); ArrayList<BrokerPlugin> plugins = new ArrayList<BrokerPlugin>(); List<AuthenticationUser> users = new ArrayList<AuthenticationUser>(); users.add(new AuthenticationUser("admin", "admin", "admins")); SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users); plugins.add(authenticationPlugin); plugins.add(configureAuthorization()); brokerService.setPlugins(plugins.toArray(new BrokerPlugin[2])); brokerService.start(); brokerService.waitUntilStarted(); }
Example 2
Source File: AMQ4889Test.java From activemq-artemis with Apache License 2.0 | 6 votes |
protected BrokerService createBroker() throws Exception { brokerService = new BrokerService(); brokerService.setPersistent(false); ArrayList<BrokerPlugin> plugins = new ArrayList<>(); BrokerPlugin authenticationPlugin = configureAuthentication(); plugins.add(authenticationPlugin); BrokerPlugin[] array = new BrokerPlugin[plugins.size()]; brokerService.setPlugins(plugins.toArray(array)); transportConnector = brokerService.addConnector(LOCAL_URI); proxyConnector = new ProxyConnector(); proxyConnector.setName("proxy"); proxyConnector.setBind(new URI(PROXY_URI)); proxyConnector.setRemote(new URI(LOCAL_URI)); brokerService.addProxyConnector(proxyConnector); brokerService.start(); brokerService.waitUntilStarted(); return brokerService; }
Example 3
Source File: ActiveMQTestBase.java From vertx-proton with Apache License 2.0 | 6 votes |
protected BrokerService createBroker(String name, boolean deleteMessagesOnStartup, Map<String, Integer> portMap) throws Exception { BrokerService brokerService = new BrokerService(); brokerService.setBrokerName(name); brokerService.setDeleteAllMessagesOnStartup(deleteMessagesOnStartup); brokerService.setUseJmx(true); brokerService.getManagementContext().setCreateConnector(false); brokerService.setDataDirectory(DATA_PARENT_DIR + File.separator + "data" + File.separator + name); brokerService.setPersistent(false); brokerService.setSchedulerSupport(false); brokerService.setAdvisorySupport(false); ArrayList<BrokerPlugin> plugins = new ArrayList<BrokerPlugin>(); BrokerPlugin authenticationPlugin = configureAuthentication(); if (authenticationPlugin != null) { plugins.add(authenticationPlugin); } if (!plugins.isEmpty()) { brokerService.setPlugins(plugins.toArray(new BrokerPlugin[0])); } addAdditionalConnectors(brokerService, portMap); return brokerService; }
Example 4
Source File: EmbeddedActiveMQ.java From james-project with Apache License 2.0 | 6 votes |
private void launchEmbeddedBroker(FileSystem fileSystem) throws Exception { brokerService = new BrokerService(); brokerService.setBrokerName(BROKER_NAME); brokerService.setUseJmx(false); brokerService.setPersistent(true); brokerService.setDataDirectoryFile(fileSystem.getFile(BROCKERS_LOCATION)); brokerService.setUseShutdownHook(false); brokerService.setSchedulerSupport(false); brokerService.setBrokerId(BROKER_ID); String[] uris = {BROCKER_URI}; brokerService.setTransportConnectorURIs(uris); ManagementContext managementContext = new ManagementContext(); managementContext.setCreateConnector(false); brokerService.setManagementContext(managementContext); brokerService.setPersistenceAdapter(persistenceAdapter); BrokerPlugin[] brokerPlugins = {new StatisticsBrokerPlugin()}; brokerService.setPlugins(brokerPlugins); String[] transportConnectorsURIs = {BROCKER_URI}; brokerService.setTransportConnectorURIs(transportConnectorsURIs); brokerService.start(); LOGGER.info("Started embedded activeMq"); }
Example 5
Source File: JmsIOTest.java From beam with Apache License 2.0 | 5 votes |
@Before public void startBroker() throws Exception { broker = new BrokerService(); broker.setUseJmx(false); broker.setPersistenceAdapter(new MemoryPersistenceAdapter()); broker.addConnector(BROKER_URL); broker.setBrokerName("localhost"); broker.setPopulateJMSXUserID(true); broker.setUseAuthenticatedPrincipalForJMSXUserID(true); // enable authentication List<AuthenticationUser> users = new ArrayList<>(); // username and password to use to connect to the broker. // This user has users privilege (able to browse, consume, produce, list destinations) users.add(new AuthenticationUser(USERNAME, PASSWORD, "users")); SimpleAuthenticationPlugin plugin = new SimpleAuthenticationPlugin(users); BrokerPlugin[] plugins = new BrokerPlugin[] {plugin}; broker.setPlugins(plugins); broker.start(); // create JMS connection factory connectionFactory = new ActiveMQConnectionFactory(BROKER_URL); connectionFactoryWithSyncAcksAndWithoutPrefetch = new ActiveMQConnectionFactory( BROKER_URL + "?jms.prefetchPolicy.all=0&jms.sendAcksAsync=false"); }
Example 6
Source File: TestJmsSource.java From datacollector with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { baseDir = Files.createTempDir(); tmpDir = new File(baseDir, "tmp"); dataDir = new File(baseDir, "data"); Assert.assertTrue(tmpDir.mkdir()); passwordFile = new File(baseDir, "password"); Files.write(PASSWORD.getBytes(StandardCharsets.UTF_8), passwordFile); broker = new BrokerService(); broker.addConnector(BROKER_BIND_URL); broker.setTmpDataDirectory(tmpDir); broker.setDataDirectoryFile(dataDir); List<AuthenticationUser> users = Lists.newArrayList(); users.add(new AuthenticationUser(USERNAME, PASSWORD, "")); SimpleAuthenticationPlugin authentication = new SimpleAuthenticationPlugin(users); broker.setPlugins(new BrokerPlugin[]{authentication}); broker.start(); basicConfig = new BasicConfig(); credentialsConfig = new CredentialsConfig(); messageConfig = new MessageConfig(); jmsSourceConfig = new JmsSourceConfig(); credentialsConfig.useCredentials = true; credentialsConfig.username = () -> USERNAME; credentialsConfig.password = () -> PASSWORD; jmsSourceConfig.initialContextFactory = INITIAL_CONTEXT_FACTORY; jmsSourceConfig.connectionFactory = CONNECTION_FACTORY; jmsSourceConfig.destinationName = JNDI_PREFIX + DESTINATION_NAME; jmsSourceConfig.providerURL = BROKER_BIND_URL; // Create a connection and start ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER_BIND_URL); connection = factory.createConnection(); connection.start(); }
Example 7
Source File: Broker.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
public Broker start() { LOGGER.info("Starting broker using brokerURL: [" + brokerURL + "]"); try { broker = new BrokerService(); broker.setPersistent(false); broker.deleteAllMessages(); broker.setDeleteAllMessagesOnStartup(true); broker.setUseJmx(false); broker.getSystemUsage().getTempUsage().setLimit(USAGE_LIMIT); broker.getSystemUsage().getStoreUsage().setLimit(USAGE_LIMIT); broker.addConnector(brokerURL); if (username != null) { AuthenticationUser user = new AuthenticationUser(username, password, "producers,consumer"); SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(); authenticationPlugin.setAnonymousAccessAllowed(false); authenticationPlugin.setUsers(singletonList(user)); broker.setPlugins(new BrokerPlugin[]{authenticationPlugin}); } broker.start(); } catch (Exception e) { throw new RuntimeException(e); } LOGGER.info("Successfully started broker"); return this; }
Example 8
Source File: SimpleSecurityBrokerSystemTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override protected BrokerService createBroker() throws Exception { BrokerService broker = super.createBroker(); broker.setPopulateJMSXUserID(true); broker.setUseAuthenticatedPrincipalForJMSXUserID(true); broker.setPlugins(new BrokerPlugin[]{authorizationPlugin, authenticationPlugin}); broker.setPersistent(false); return broker; }
Example 9
Source File: ActiveMQJmsPoolTestSupport.java From pooled-jms with Apache License 2.0 | 5 votes |
protected String createBroker() throws Exception { brokerService = new BrokerService(); brokerService.setDeleteAllMessagesOnStartup(true); brokerService.setPersistent(false); brokerService.setUseJmx(true); brokerService.getManagementContext().setCreateConnector(false); brokerService.getManagementContext().setCreateMBeanServer(false); brokerService.setAdvisorySupport(false); brokerService.setSchedulerSupport(false); brokerService.addConnector("tcp://localhost:0").setName("test"); ArrayList<BrokerPlugin> plugins = new ArrayList<BrokerPlugin>(); List<AuthenticationUser> users = new ArrayList<AuthenticationUser>(); users.add(new AuthenticationUser(USER, USER_PASSWORD, "users")); users.add(new AuthenticationUser(GUEST, USER_PASSWORD, "guests")); users.add(new AuthenticationUser(ADMIN, ADMIN, "admins")); SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users); authenticationPlugin.setAnonymousAccessAllowed(true); plugins.add(authenticationPlugin); plugins.add(configureAuthorization()); brokerService.setPlugins(plugins.toArray(new BrokerPlugin[2])); brokerService.start(); brokerService.waitUntilStarted(); return brokerService.getTransportConnectorByName("test").getPublishableConnectString(); }
Example 10
Source File: SecureDLQTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override protected BrokerService createBroker() throws Exception { BrokerService broker = super.createBroker(); AuthorizationPlugin authorizationPlugin = new AuthorizationPlugin(createAuthorizationMap()); broker.setPlugins(new BrokerPlugin[]{authorizationPlugin, new SimpleSecurityBrokerSystemTest.SimpleAuthenticationFactory()}); return broker; }
Example 11
Source File: DestinationsPluginTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected BrokerService createBroker() { BrokerService broker = new BrokerService(); broker.setPersistent(false); broker.setUseJmx(true); broker.setPlugins(new BrokerPlugin[]{new DestinationsPlugin()}); broker.setDataDirectory("target/test"); return broker; }
Example 12
Source File: ExceptionListenerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@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 13
Source File: QpidJmsTestSupport.java From qpid-jms with Apache License 2.0 | 4 votes |
protected BrokerService createBroker(String name, boolean deleteAllMessages, Map<String, Integer> portMap) throws Exception { BrokerService brokerService = new BrokerService(); brokerService.setBrokerName(name); brokerService.setPersistent(isPersistent()); brokerService.setSchedulerSupport(isSchedulerSupport()); brokerService.setAdvisorySupport(isAdvisorySupport()); brokerService.setDeleteAllMessagesOnStartup(deleteAllMessages); brokerService.setUseJmx(true); brokerService.getManagementContext().setCreateConnector(false); brokerService.setDataDirectory("target/" + name); brokerService.setKeepDurableSubsActive(false); if (isPersistent()) { KahaDBStore kaha = new KahaDBStore(); kaha.setDirectory(new File(KAHADB_DIRECTORY + "/" + name)); kaha.setConcurrentStoreAndDispatchQueues(isConcurrentStoreAndDispatchQueues()); kaha.setConcurrentStoreAndDispatchTopics(isConcurrentStoreAndDispatchTopics()); kaha.setCheckpointInterval(TimeUnit.MINUTES.toMillis(5)); brokerService.setPersistenceAdapter(kaha); } configureBrokerPolicies(brokerService); ArrayList<BrokerPlugin> plugins = new ArrayList<BrokerPlugin>(); BrokerPlugin authenticationPlugin = configureAuthentication(); if (authenticationPlugin != null) { plugins.add(authenticationPlugin); } BrokerPlugin authorizationPlugin = configureAuthorization(); if (authorizationPlugin != null) { plugins.add(authorizationPlugin); } addAdditionalBrokerPlugins(plugins); if (!plugins.isEmpty()) { BrokerPlugin[] array = new BrokerPlugin[plugins.size()]; brokerService.setPlugins(plugins.toArray(array)); } addAdditionalConnectors(brokerService, portMap); return brokerService; }
Example 14
Source File: BrokerExtension.java From james-project with Apache License 2.0 | 4 votes |
private void enableStatistics(BrokerService broker) { broker.setPlugins(new BrokerPlugin[]{new StatisticsBrokerPlugin()}); broker.setEnableStatistics(true); }
Example 15
Source File: TimeStampTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
public void test() throws Exception { BrokerService broker = new BrokerService(); broker.setPersistent(false); broker.setUseJmx(true); broker.setPlugins(new BrokerPlugin[]{new ConnectionDotFilePlugin(), new UDPTraceBrokerPlugin()}); TransportConnector tcpConnector = broker.addConnector("tcp://localhost:0"); broker.addConnector("stomp://localhost:0"); broker.start(); // Create a ConnectionFactory ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(tcpConnector.getConnectUri()); // Create a Connection Connection connection = connectionFactory.createConnection(); connection.start(); // Create a Session Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Create the destination Queue Destination destination = session.createQueue("TEST.FOO"); // Create a MessageProducer from the Session to the Topic or Queue MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); // Create a messages Message sentMessage = session.createMessage(); // Tell the producer to send the message long beforeSend = System.currentTimeMillis(); producer.send(sentMessage); long afterSend = System.currentTimeMillis(); // assert message timestamp is in window assertTrue(beforeSend <= sentMessage.getJMSTimestamp() && sentMessage.getJMSTimestamp() <= afterSend); // Create a MessageConsumer from the Session to the Topic or Queue MessageConsumer consumer = session.createConsumer(destination); // Wait for a message Message receivedMessage = consumer.receive(1000); // assert we got the same message ID we sent assertEquals(sentMessage.getJMSMessageID(), receivedMessage.getJMSMessageID()); // assert message timestamp is in window assertTrue("JMS Message Timestamp should be set during the send method: \n" + " beforeSend = " + beforeSend + "\n" + " getJMSTimestamp = " + receivedMessage.getJMSTimestamp() + "\n" + " afterSend = " + afterSend + "\n", beforeSend <= receivedMessage.getJMSTimestamp() && receivedMessage.getJMSTimestamp() <= afterSend); // assert message timestamp is unchanged assertEquals("JMS Message Timestamp of received message should be the same as the sent message\n ", sentMessage.getJMSTimestamp(), receivedMessage.getJMSTimestamp()); // Clean up producer.close(); consumer.close(); session.close(); connection.close(); }
Example 16
Source File: TwoBrokerQueueClientsReconnectTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
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()); }
Example 17
Source File: TwoBrokerQueueClientsReconnectTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
public void testDuplicateSend() throws Exception { broker1 = "BrokerA"; broker2 = "BrokerB"; // enable producer audit for the network connector, off by default b/c of interference with composite // dests and virtual topics brokers.get(broker2).broker.getTransportConnectors().get(0).setAuditNetworkProducers(true); 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); 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(); } } }}); // Run brokers startAllBrokers(); waitForBridgeFormation(); // Create queue Destination dest = createDestination("TEST.FOO", false); MessageConsumer client2 = createConsumer(broker2, dest); sendMessages("BrokerA", dest, 1); assertEquals("Client got message", 1, receiveExactMessages(client2, 1)); client2.close(); gotMessageLatch.countDown(); // message still pending on broker1 assertEquals("messages message still there", 1, brokers.get(broker1).broker.getAdminView().getTotalMessageCount()); client2 = createConsumer(broker2, dest); LOG.info("Let the second client receive the rest of the messages"); assertEquals("no duplicate message", 0, receiveAllMessages(client2)); assertEquals("no duplicate message", 0, receiveAllMessages(client2)); assertEquals("no messages enqueued", 0, brokers.get(broker2).broker.getAdminView().getTotalMessageCount()); 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(); } })); }
Example 18
Source File: TimeStampingBrokerPluginTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override @Before public void setUp() throws Exception { TimeStampingBrokerPlugin tsbp = new TimeStampingBrokerPlugin(); tsbp.setZeroExpirationOverride(expiry); tsbp.setTtlCeiling(expiry); broker = new BrokerService(); broker.setPersistent(false); broker.setUseJmx(true); broker.setPlugins(new BrokerPlugin[]{tsbp}); tcpConnector = broker.addConnector("tcp://localhost:0"); // Add policy and individual DLQ strategy PolicyEntry policy = new PolicyEntry(); DeadLetterStrategy strategy = new IndividualDeadLetterStrategy(); strategy.setProcessExpired(true); ((IndividualDeadLetterStrategy) strategy).setUseQueueForQueueMessages(true); ((IndividualDeadLetterStrategy) strategy).setQueuePrefix("DLQ."); strategy.setProcessNonPersistent(true); policy.setDeadLetterStrategy(strategy); PolicyMap pMap = new PolicyMap(); pMap.setDefaultEntry(policy); broker.setDestinationPolicy(pMap); broker.start(); // Create a ConnectionFactory ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(tcpConnector.getConnectUri()); // Create a Connection connection = connectionFactory.createConnection(); connection.start(); // Create a Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Create the destination Queue destination = session.createQueue(queue); // Create a MessageProducer from the Session to the Topic or Queue producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); }
Example 19
Source File: TraceBrokerPathPluginTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@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 20
Source File: TestIntegrationActiveMQ.java From mt-flume with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Before public void setup() throws Exception { baseDir = Files.createTempDir(); tmpDir = new File(baseDir, "tmp"); dataDir = new File(baseDir, "data"); Assert.assertTrue(tmpDir.mkdir()); passwordFile = new File(baseDir, "password"); Files.write(PASSWORD.getBytes(Charsets.UTF_8), passwordFile); broker = new BrokerService(); broker.addConnector(BROKER_BIND_URL); broker.setTmpDataDirectory(tmpDir); broker.setDataDirectoryFile(dataDir); List<AuthenticationUser> users = Lists.newArrayList(); users.add(new AuthenticationUser(USERNAME, PASSWORD, "")); SimpleAuthenticationPlugin authentication = new SimpleAuthenticationPlugin(users); broker.setPlugins(new BrokerPlugin[]{authentication}); broker.start(); context = new Context(); context.put(JMSSourceConfiguration.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); context.put(JMSSourceConfiguration.PROVIDER_URL, BROKER_BIND_URL); context.put(JMSSourceConfiguration.DESTINATION_NAME, DESTINATION_NAME); context.put(JMSSourceConfiguration.USERNAME, USERNAME); context.put(JMSSourceConfiguration.PASSWORD_FILE, passwordFile.getAbsolutePath()); events = Lists.newArrayList(); source = new JMSSource(); source.setName("JMSSource-" + UUID.randomUUID()); ChannelProcessor channelProcessor = mock(ChannelProcessor.class); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { events.addAll((List<Event>)invocation.getArguments()[0]); return null; } }).when(channelProcessor).processEventBatch(any(List.class)); source.setChannelProcessor(channelProcessor); }