org.apache.activemq.broker.BrokerPlugin Java Examples
The following examples show how to use
org.apache.activemq.broker.BrokerPlugin.
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: 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 #3
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 #4
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 #5
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 #6
Source File: ActiveMQ5Factory.java From tomee with Apache License 2.0 | 5 votes |
private BrokerPlugin[] createPlugins(final Map<String, String> params) { final String plugins = params.remove("amq.plugins"); if (plugins == null) { return null; } final Collection<BrokerPlugin> instances = new LinkedList<>(); for (final String p : plugins.split(" *, *")) { if (p.isEmpty()) { continue; } final String prefix = p + "."; final ObjectRecipe recipe = new ObjectRecipe(params.remove(prefix + "class")); final Iterator<Map.Entry<String, String>> iterator = params.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<String, String> entry = iterator.next(); final String key = entry.getKey(); if (key.startsWith(prefix)) { recipe.setProperty(key.substring(prefix.length()), entry.getValue()); iterator.remove(); } } instances.add(BrokerPlugin.class.cast(recipe.create())); } return instances.toArray(new BrokerPlugin[instances.size()]); }
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: QpidJmsTestSupport.java From qpid-jms with Apache License 2.0 | 5 votes |
protected BrokerPlugin configureAuthentication() throws Exception { List<AuthenticationUser> users = new ArrayList<AuthenticationUser>(); users.add(new AuthenticationUser("system", "manager", "users,admins")); users.add(new AuthenticationUser("user", "password", "users")); users.add(new AuthenticationUser("guest", "password", "guests")); SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users); authenticationPlugin.setAnonymousAccessAllowed(true); return authenticationPlugin; }
Example #9
Source File: ActiveMQTestBase.java From vertx-proton with Apache License 2.0 | 5 votes |
protected BrokerPlugin configureAuthentication() throws Exception { List<AuthenticationUser> users = new ArrayList<AuthenticationUser>(); users.add(new AuthenticationUser(USERNAME_ADMIN, PASSWORD_ADMIN, "users,admins")); users.add(new AuthenticationUser(USERNAME_USER, PASSWORD_USER, "users")); users.add(new AuthenticationUser(USERNAME_GUEST, PASSWORD_GUEST, "guests")); SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users); authenticationPlugin.setAnonymousAccessAllowed(isAnonymousAccessAllowed()); return authenticationPlugin; }
Example #10
Source File: AuthorizationFromAdminViewTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void createBroker() throws Exception { broker = BrokerFactory.createBroker("broker:(vm://localhost)"); broker.setPersistent(false); broker.setBrokerName(getName()); AuthorizationPlugin plugin = new AuthorizationPlugin(); plugin.setMap(new SimpleAuthorizationMap()); BrokerPlugin[] plugins = new BrokerPlugin[]{plugin}; broker.setPlugins(plugins); broker.start(); }
Example #11
Source File: JMSBroker.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Starting ActiveMQ embedded broker after specifying plugins. * * @param brokerPlugins the array of BrokerPlugins to be set * @return whether or not the broker was stated successfully */ public boolean startWithPlugins(BrokerPlugin[] brokerPlugins) { try { setInitialConfigurations(); broker.setPlugins(brokerPlugins); startBroker(); return true; } catch (Exception e) { log.error("JMSServerController: There was an error starting JMS broker: " + serverName, e); return false; } }
Example #12
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 #13
Source File: TestJmsTarget.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(); credentialsConfig = new CredentialsConfig(); jmsTargetConfig = new JmsTargetConfig(); credentialsConfig.useCredentials = true; credentialsConfig.username = () -> USERNAME; credentialsConfig.password = () -> PASSWORD; jmsTargetConfig.destinationName = JNDI_PREFIX + DESTINATION_NAME; jmsTargetConfig.initialContextFactory = INITIAL_CONTEXT_FACTORY; jmsTargetConfig.connectionFactory = CONNECTION_FACTORY; jmsTargetConfig.providerURL = BROKER_BIND_URL; // Create a connection and start ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER_BIND_URL); connection = factory.createConnection(); connection.start(); }
Example #14
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 #15
Source File: JMSBroker.java From product-ei with Apache License 2.0 | 5 votes |
/** * Starting ActiveMQ embedded broker after specifying plugins. * * @param brokerPlugins the array of BrokerPlugins to be set * @return whether or not the broker was stated successfully */ public boolean startWithPlugins(BrokerPlugin[] brokerPlugins) { try { setInitialConfigurations(); broker.setPlugins(brokerPlugins); startBroker(); return true; } catch (Exception e) { log.error("JMSServerController: There was an error starting JMS broker: " + serverName, e); return false; } }
Example #16
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 #17
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 #18
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 #19
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 #20
Source File: BrokerStatisticsPluginTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected BrokerService createBroker() throws Exception { BrokerService answer = new BrokerService(); BrokerPlugin[] plugins = new BrokerPlugin[1]; plugins[0] = new StatisticsBrokerPlugin(); answer.setPlugins(plugins); answer.setDeleteAllMessagesOnStartup(true); answer.addConnector("tcp://localhost:0"); answer.start(); return answer; }
Example #21
Source File: AMQ4889Test.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected BrokerPlugin configureAuthentication() throws Exception { List<AuthenticationUser> users = new ArrayList<>(); users.add(new AuthenticationUser(USER, GOOD_USER_PASSWORD, "users")); SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users); return authenticationPlugin; }
Example #22
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 #23
Source File: BrokerQueueNetworkWithDisconnectTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
public void testNoStuckConnectionsWithTransportDisconnect() throws Exception { inactiveDuration = 60000L; useDuplexNetworkBridge = true; bridgeBrokers(SPOKE, HUB); final BrokerItem hub = brokers.get(HUB); hub.broker.setPlugins(new BrokerPlugin[]{new BrokerPluginSupport() { int sleepCount = 2; @Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { try { while (--sleepCount >= 0) { LOG.info("sleeping for a bit in close impl to simulate load where reconnect fails due to a pending close"); TimeUnit.SECONDS.sleep(2); } } catch (Exception ignored) { } super.removeConnection(context, info, error); } }}); startAllBrokers(); waitForBridgeFormation(); // kill the initiator side, leaving remote end intact // simulate async network breakage // remote side will need to spot duplicate network and stop/kill the original for (int i = 0; i < 3; i++) { socketProxy.halfClose(); sleep(10000); } // wait for full reformation of bridge // verify no extra connections boolean allGood = Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { long numConnections = hub.broker.getTransportConnectors().get(0).getConnections().size(); LOG.info("Num connetions:" + numConnections); return numConnections == 1; } }); if (!allGood) { dumpAllThreads("ExtraHubConnection"); } assertTrue("should be only one transport connection for the single duplex network connector", allGood); allGood = Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { long numVmConnections = VMTransportFactory.SERVERS.get(HUB).getConnectionCount(); LOG.info("Num VM connetions:" + numVmConnections); return numVmConnections == 2; } }); if (!allGood) { dumpAllThreads("ExtraHubVMConnection"); } assertTrue("should be only 2 vm connections for the single network duplex network connector", allGood); }
Example #24
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 #25
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 #26
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 #27
Source File: IgniteJmsStreamerTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Test for ExceptionListener functionality. * * @throws Exception If fails. */ @Test public void testExceptionListener() throws Exception { // restart broker with auth plugin if (broker.isStarted()) broker.stop(); broker.waitUntilStopped(); broker.setPlugins(new BrokerPlugin[]{new SimpleAuthenticationPlugin(new ArrayList())}); broker.start(true); connFactory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI()); final List<Throwable> lsnrExceptions = new LinkedList<>(); final CountDownLatch latch = new CountDownLatch(1); Destination dest = new ActiveMQQueue(QUEUE_NAME); try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) { JmsStreamer<ObjectMessage, String, String> jmsStreamer = newJmsStreamer(ObjectMessage.class, dataStreamer); jmsStreamer.setExceptionListener(new ExceptionListener() { @Override public void onException(JMSException e) { System.out.println("ERROR"); lsnrExceptions.add(e); latch.countDown(); } }); jmsStreamer.setDestination(dest); GridTestUtils.assertThrowsWithCause(new Callable<Void>() { @Override public Void call() throws Exception { jmsStreamer.start(); return null; } }, SecurityException.class); assertTrue(latch.await(10, TimeUnit.SECONDS)); assertTrue(lsnrExceptions.size() > 0); GridTestUtils.assertThrowsWithCause(new Callable<Void>() { @Override public Void call() throws Exception { jmsStreamer.stop(); return null; } }, IgniteException.class); } }
Example #28
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 #29
Source File: QpidJmsTestSupport.java From qpid-jms with Apache License 2.0 | 4 votes |
protected void addAdditionalBrokerPlugins(List<BrokerPlugin> plugins) { // Subclasses can add their own plugins, we don't add any here. }
Example #30
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); }