org.apache.activemq.artemis.api.jms.ActiveMQJMSClient Java Examples
The following examples show how to use
org.apache.activemq.artemis.api.jms.ActiveMQJMSClient.
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: StompTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void sendMessageToNonExistentQueue(String queuePrefix, String queue, RoutingType routingType) throws Exception { conn.connect(defUser, defPass); send(conn, queuePrefix + queue, null, "Hello World", true, routingType); MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue(queue)); TextMessage message = (TextMessage) consumer.receive(1000); Assert.assertNotNull(message); Assert.assertEquals("Hello World", message.getText()); // Assert default priority 4 is used when priority header is not set Assert.assertEquals("getJMSPriority", 4, message.getJMSPriority()); // Make sure that the timestamp is valid - should // be very close to the current time. long tnow = System.currentTimeMillis(); long tmsg = message.getJMSTimestamp(); Assert.assertTrue(Math.abs(tnow - tmsg) < 1500); // closing the consumer here should trigger auto-deletion assertNotNull(server.getPostOffice().getBinding(new SimpleString(queue))); consumer.close(); Wait.assertTrue(() -> server.getPostOffice().getBinding(new SimpleString(queue)) == null); }
Example #2
Source File: AutoCreateJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testAutoCreateOnDurableSubscribeToTopic() throws Exception { Connection connection = cf.createConnection(); connection.setClientID("myClientID"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Topic topic = ActiveMQJMSClient.createTopic(QUEUE_NAME); MessageConsumer consumer = session.createDurableConsumer(topic, "myDurableSub"); MessageProducer producer = session.createProducer(topic); producer.send(session.createTextMessage("msg")); connection.start(); assertNotNull(consumer.receive(500)); connection.close(); assertNotNull(server.getManagementService().getResource(ResourceNames.ADDRESS + "test")); assertNotNull(server.locateQueue(SimpleString.toSimpleString("myClientID.myDurableSub"))); }
Example #3
Source File: EmbeddedTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
public static void publish(String destination, Serializable object, String contentType) throws Exception { ConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("vm://0","cf"); Connection conn = factory.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination dest = session.createQueue(destination); try { Assert.assertNotNull("Destination was null", dest); MessageProducer producer = session.createProducer(dest); ObjectMessage message = session.createObjectMessage(); if (contentType != null) { message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType); } message.setObject(object); producer.send(message); } finally { conn.close(); } }
Example #4
Source File: AutoCreateJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testAutoCreateOnSubscribeToTopic() throws Exception { Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); final String topicName = "test-" + UUID.randomUUID().toString(); javax.jms.Topic topic = ActiveMQJMSClient.createTopic(topicName); MessageConsumer consumer = session.createConsumer(topic); MessageProducer producer = session.createProducer(topic); producer.send(session.createTextMessage("msg")); connection.start(); assertNotNull(consumer.receive(500)); assertNotNull(server.getManagementService().getResource(ResourceNames.ADDRESS + topicName)); connection.close(); assertNull(server.getManagementService().getResource(ResourceNames.ADDRESS + topicName)); }
Example #5
Source File: JmsConsumerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSharedDurableConsumer() throws Exception { conn = cf.createConnection(); conn.start(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); topic = ActiveMQJMSClient.createTopic(T_NAME); MessageConsumer cons = session.createSharedDurableConsumer(topic, "test1"); MessageProducer producer = session.createProducer(topic); producer.send(session.createTextMessage("test")); TextMessage txt = (TextMessage) cons.receive(5000); Assert.assertNotNull(txt); }
Example #6
Source File: JmsConsumerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSharedConsumer() throws Exception { conn = cf.createConnection(); conn.start(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); topic = ActiveMQJMSClient.createTopic(T_NAME); MessageConsumer cons = session.createSharedConsumer(topic, "test1"); MessageProducer producer = session.createProducer(topic); producer.send(session.createTextMessage("test")); TextMessage txt = (TextMessage) cons.receive(5000); Assert.assertNotNull(txt); }
Example #7
Source File: AutoCreateJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testAutoCreateOnConsumeFromFQQN() throws Exception { Connection connection = null; connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String queueName = RandomUtil.randomString(); String addressName = RandomUtil.randomString(); javax.jms.Queue queue = ActiveMQJMSClient.createQueue(CompositeAddress.toFullyQualified(addressName, queueName)); MessageConsumer messageConsumer = session.createConsumer(queue); connection.start(); Message m = messageConsumer.receive(500); Assert.assertNull(m); Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString(queueName)).getBindable(); Assert.assertEquals(0, q.getMessageCount()); Assert.assertEquals(0, q.getMessagesAdded()); connection.close(); }
Example #8
Source File: ArtemisJMSClientFeatureIT.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testArtemisJMSClient() throws Exception { // setup connection ConnectionFactory cf = new ActiveMQJMSConnectionFactory("tcp://localhost:61616"); try (Connection connection = cf.createConnection()) { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); connection.start(); Queue queue = ActiveMQJMSClient.createQueue("artemisJMSClientFeatureITQueue"); MessageProducer producer = session.createProducer(queue); // send message String textMessage = "This is a text message"; TextMessage message = session.createTextMessage(textMessage); producer.send(message); // receive message and assert MessageConsumer messageConsumer = session.createConsumer(queue); TextMessage messageReceived = (TextMessage) messageConsumer.receive(100); assertEquals(textMessage, messageReceived.getText()); } }
Example #9
Source File: BrokerProducerThread.java From OpenIoE with Apache License 2.0 | 6 votes |
public void StartBrokerProducer() throws JMSException { Connection connection = null; try { ConnectionFactory cf = new ActiveMQConnectionFactory(ioeConfiguration.getTopic().getTopicUrl()); connection = cf.createConnection(ioeConfiguration.getTopic().getUsername(), ioeConfiguration.getTopic().getPassword()); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // TODO - Read message payload from cassandra String payload = "{\"data\": \"36\",\"description\": \"test\",\"sensorId\": 1, \"timestamp\": \"2015-06-19T11:07:44.526Z\", \"topic\": \"topic\"}"; Message msg = session.createTextMessage(payload); //TODO Read topic value from the sensor data or publication entity Topic topic = ActiveMQJMSClient.createTopic("ioe"); MessageProducer messageProducer = session.createProducer(null); messageProducer.send(topic,msg); connection.start(); } catch (Exception ex) { ex.printStackTrace(); } }
Example #10
Source File: AutoCreateJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testAutoCreateOnSendToQueueSecurity() throws Exception { ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("guest", "guest"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().setDefaultUser("guest"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("guest", "rejectAll"); Role role = new Role("rejectAll", false, false, false, false, false, false, false, false, false, false); Set<Role> roles = new HashSet<>(); roles.add(role); server.getSecurityRepository().addMatch("#", roles); Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = ActiveMQJMSClient.createQueue(QUEUE_NAME); try { session.createProducer(queue); Assert.fail("Sending a message here should throw a JMSSecurityException"); } catch (Exception e) { Assert.assertTrue(e instanceof JMSSecurityException); } connection.close(); }
Example #11
Source File: JMSAutoCloseableExample.java From activemq-artemis with Apache License 2.0 | 6 votes |
public static void main(final String[] args) throws Exception { // Step 2. Perfom a lookup on the queue Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); // Step 4.Create a JMS Context using the try-with-resources statement try ( // Even though ConnectionFactory is not closeable it would be nice to close an ActiveMQConnectionFactory ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); JMSContext jmsContext = cf.createContext() ) { // Step 5. create a jms producer JMSProducer jmsProducer = jmsContext.createProducer(); // Step 6. Try sending a message, we don't have the appropriate privileges to do this so this will throw an exception jmsProducer.send(queue, "A Message from JMS2!"); System.out.println("Received:" + jmsContext.createConsumer(queue).receiveBody(String.class)); } }
Example #12
Source File: ConnectionFactoryURITest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testJGroupsFileURI() throws Exception { DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration(); JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName("channel-name").setFile("channel-file.xml"); discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpointFactory); ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF); URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA); ActiveMQConnectionFactory factory = parser.newObject(tcp, null); DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration(); Assert.assertNotNull(dgc); BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory(); Assert.assertNotNull(befc); Assert.assertTrue(befc instanceof JGroupsFileBroadcastEndpointFactory); Assert.assertEquals(dgc.getName(), "foo"); Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678); Assert.assertEquals(dgc.getRefreshTimeout(), 12345); JGroupsFileBroadcastEndpointFactory fileBroadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) befc; Assert.assertEquals(fileBroadcastEndpointFactory.getFile(), "channel-file.xml"); Assert.assertEquals(fileBroadcastEndpointFactory.getChannelName(), "channel-name"); BeanUtilsBean bean = new BeanUtilsBean(); checkEquals(bean, connectionFactoryWithHA, factory); }
Example #13
Source File: AcknowledgementTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Ensure no blocking calls in acknowledge flow when block on acknowledge = false. * This is done by checking the performance compared to blocking is much improved. */ @Test public void testNonBlockingAckPerf() throws Exception { ConnectionFactory cf1 = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616?blockOnNonDurableSend=true&blockOnAcknowledge=false", "testsuitecf1"); ConnectionFactory cf2 = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616?blockOnNonDurableSend=true&blockOnAcknowledge=true", "testsuitecf2"); int messageCount = 100; long sendT1 = send(cf1, queue1, messageCount); long sendT2 = send(cf2, queue2, messageCount); long time1 = consume(cf1, queue1, messageCount); long time2 = consume(cf2, queue2, messageCount); log.debug("BlockOnAcknowledge=false MessageCount=" + messageCount + " TimeToConsume=" + time1); log.debug("BlockOnAcknowledge=true MessageCount=" + messageCount + " TimeToConsume=" + time2); Assert.assertTrue(time1 < (time2 / 2)); }
Example #14
Source File: OutgoingConnectionNoJTATest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSimpleSendNoXAJMS1() throws Exception { Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); try (ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(); ClientConsumer consVerify = session.createConsumer(MDBQUEUE); Connection conn = qraConnectionFactory.createConnection(); ) { Session jmsSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); session.start(); MessageProducer producer = jmsSess.createProducer(q); // These next 4 lines could be written in a single line however it makes difficult for debugging TextMessage msgsend = jmsSess.createTextMessage("hello"); msgsend.setStringProperty("strvalue", "hello"); producer.send(msgsend); ClientMessage msg = consVerify.receive(1000); assertNotNull(msg); assertEquals("hello", msg.getStringProperty("strvalue")); } }
Example #15
Source File: OutgoingConnectionNoJTATest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSimpleSendNoXAJMSContext() throws Exception { Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); try (ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(); ClientConsumer consVerify = session.createConsumer(MDBQUEUE); JMSContext jmsctx = qraConnectionFactory.createContext(); ) { session.start(); // These next 4 lines could be written in a single line however it makes difficult for debugging JMSProducer producer = jmsctx.createProducer(); producer.setProperty("strvalue", "hello"); TextMessage msgsend = jmsctx.createTextMessage("hello"); producer.send(q, msgsend); ClientMessage msg = consVerify.receive(1000); assertNotNull(msg); assertEquals("hello", msg.getStringProperty("strvalue")); } }
Example #16
Source File: JmsConsumerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testPreCommitAcks() throws Exception { conn = cf.createConnection(); Session session = conn.createSession(false, ActiveMQJMSConstants.PRE_ACKNOWLEDGE); jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME); MessageProducer producer = session.createProducer(jBossQueue); MessageConsumer consumer = session.createConsumer(jBossQueue); int noOfMessages = 100; for (int i = 0; i < noOfMessages; i++) { producer.send(session.createTextMessage("m" + i)); } conn.start(); for (int i = 0; i < noOfMessages; i++) { Message m = consumer.receive(500); Assert.assertNotNull(m); } SimpleString queueName = new SimpleString(JmsConsumerTest.Q_NAME); Assert.assertEquals(0, getMessageCount((Queue) server.getPostOffice().getBinding(queueName).getBindable())); Assert.assertEquals(0, getMessageCount((Queue) server.getPostOffice().getBinding(queueName).getBindable())); }
Example #17
Source File: OutgoingConnectionJTATest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSimpleSendNoXAJMS1() throws Exception { Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); try (ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(); ClientConsumer consVerify = session.createConsumer(MDBQUEUE); Connection conn = qraConnectionFactory.createConnection(); ) { Session jmsSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); session.start(); MessageProducer producer = jmsSess.createProducer(q); // These next 4 lines could be written in a single line however it makes difficult for debugging TextMessage msgsend = jmsSess.createTextMessage("hello"); msgsend.setStringProperty("strvalue", "hello"); producer.send(msgsend); ClientMessage msg = consVerify.receive(1000); assertNotNull(msg); assertEquals("hello", msg.getStringProperty("strvalue")); } }
Example #18
Source File: OutgoingConnectionJTATest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSimpleSendNoXAJMSContext() throws Exception { Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); try (ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(); ClientConsumer consVerify = session.createConsumer(MDBQUEUE); JMSContext jmsctx = qraConnectionFactory.createContext(); ) { session.start(); // These next 4 lines could be written in a single line however it makes difficult for debugging JMSProducer producer = jmsctx.createProducer(); producer.setProperty("strvalue", "hello"); TextMessage msgsend = jmsctx.createTextMessage("hello"); producer.send(q, msgsend); ClientMessage msg = consVerify.receive(1000); assertNotNull(msg); assertEquals("hello", msg.getStringProperty("strvalue")); } }
Example #19
Source File: ReplyToTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Before @Override public void setUp() throws Throwable { FileUtil.deleteDirectory(serverFolder.getRoot()); serverFolder.getRoot().mkdirs(); File file = serverFolder.newFile(ActiveMQJMSClient.class.getName() + ".properties"); FileOutputStream fileOutputStream = new FileOutputStream(file); PrintStream stream = new PrintStream(fileOutputStream); stream.println("enable1xPrefixes=true"); stream.close(); setVariable(serverClassloader, "persistent", Boolean.FALSE); startServer(serverFolder.getRoot(), serverClassloader, "live"); }
Example #20
Source File: ConnectionFactoryProvider.java From activemq-artemis with Apache License 2.0 | 6 votes |
private ActiveMQConnectionFactory createConnectionFactory() throws Exception { Map<String, Object> params = new HashMap<>(); params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1"); final ActiveMQConnectionFactory activeMQConnectionFactory; if (configuration.getUrl() != null) { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactory(configuration.getUrl(), null); } else { if (configuration.getHost() != null) { params.put(TransportConstants.HOST_PROP_NAME, configuration.getHost()); params.put(TransportConstants.PORT_PROP_NAME, configuration.getPort()); } if (configuration.isHa()) { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params)); } else { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params)); } } if (configuration.hasAuthentication()) { activeMQConnectionFactory.setUser(configuration.getUsername()); activeMQConnectionFactory.setPassword(configuration.getPassword()); } // The CF will probably be GCed since it was injected, so we disable the finalize check return activeMQConnectionFactory.disableFinalizeChecks(); }
Example #21
Source File: JmsConsumerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testPreCommitAcksWithMessageExpiry() throws Exception { conn = cf.createConnection(); Session session = conn.createSession(false, ActiveMQJMSConstants.PRE_ACKNOWLEDGE); jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME); MessageProducer producer = session.createProducer(jBossQueue); MessageConsumer consumer = session.createConsumer(jBossQueue); int noOfMessages = 1000; for (int i = 0; i < noOfMessages; i++) { TextMessage textMessage = session.createTextMessage("m" + i); producer.setTimeToLive(1); producer.send(textMessage); } Thread.sleep(2); conn.start(); Message m = consumer.receiveNoWait(); Assert.assertNull(m); // Asserting delivering count is zero is bogus since messages might still be being delivered and expired at this // point // which can cause delivering count to flip to 1 }
Example #22
Source File: JmsConsumerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testPreCommitAcksWithMessageExpirySetOnConnectionFactory() throws Exception { ((ActiveMQConnectionFactory) cf).setPreAcknowledge(true); conn = cf.createConnection(); Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME); MessageProducer producer = session.createProducer(jBossQueue); MessageConsumer consumer = session.createConsumer(jBossQueue); int noOfMessages = 1000; for (int i = 0; i < noOfMessages; i++) { TextMessage textMessage = session.createTextMessage("m" + i); producer.setTimeToLive(1); producer.send(textMessage); } Thread.sleep(2); conn.start(); Message m = consumer.receiveNoWait(); Assert.assertNull(m); // Asserting delivering count is zero is bogus since messages might still be being delivered and expired at this // point // which can cause delivering count to flip to 1 }
Example #23
Source File: AutoDeleteJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testAutoDeleteTopicDurableSubscriber() throws Exception { Connection connection = cf.createConnection(); connection.setClientID("myClientID"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Topic topic = ActiveMQJMSClient.createTopic("test"); MessageConsumer messageConsumer = session.createDurableConsumer(topic, "mySub"); MessageProducer producer = session.createProducer(topic); final int numMessages = 100; for (int i = 0; i < numMessages; i++) { TextMessage mess = session.createTextMessage("msg" + i); producer.send(mess); } producer.close(); connection.start(); for (int i = 0; i < numMessages; i++) { Message m = messageConsumer.receive(5000); Assert.assertNotNull(m); } messageConsumer.close(); session.unsubscribe("mySub"); connection.close(); // ensure the topic was removed Assert.assertNull(server.locateQueue(new SimpleString("test"))); // make sure the JMX control was removed for the JMS topic assertNull(server.getManagementService().getResource("test")); }
Example #24
Source File: StompTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void sendMessageToNonExistentTopic(String topicPrefix, String topic, RoutingType routingType) throws Exception { conn.connect(defUser, defPass); // first send a message to ensure that sending to a non-existent topic won't throw an error send(conn, topicPrefix + topic, null, "Hello World", true, routingType); // create a subscription on the topic and send/receive another message MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createTopic(topic)); send(conn, topicPrefix + topic, null, "Hello World", true, routingType); TextMessage message = (TextMessage) consumer.receive(1000); Assert.assertNotNull(message); Assert.assertEquals("Hello World", message.getText()); // Assert default priority 4 is used when priority header is not set Assert.assertEquals("getJMSPriority", 4, message.getJMSPriority()); // Make sure that the timestamp is valid - should // be very close to the current time. long tnow = System.currentTimeMillis(); long tmsg = message.getJMSTimestamp(); Assert.assertTrue(Math.abs(tnow - tmsg) < 1500); assertNotNull(server.getAddressInfo(new SimpleString(topic))); // closing the consumer here should trigger auto-deletion of the subscription queue and address consumer.close(); Thread.sleep(200); assertNull(server.getAddressInfo(new SimpleString(topic))); }
Example #25
Source File: JmsConsumerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override @Before public void setUp() throws Exception { super.setUp(); topic = ActiveMQJMSClient.createTopic(T_NAME); topic2 = ActiveMQJMSClient.createTopic(T2_NAME); jmsServer.createQueue(false, JmsConsumerTest.Q_NAME, null, true, JmsConsumerTest.Q_NAME); jmsServer.createTopic(true, T_NAME, "/topic/" + T_NAME); jmsServer.createTopic(true, T2_NAME, "/topic/" + T2_NAME); cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY)); }
Example #26
Source File: AutoDeleteJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testAutoDeleteTopic() throws Exception { Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Topic topic = ActiveMQJMSClient.createTopic("test"); MessageConsumer messageConsumer = session.createConsumer(topic); MessageProducer producer = session.createProducer(topic); final int numMessages = 100; for (int i = 0; i < numMessages; i++) { TextMessage mess = session.createTextMessage("msg" + i); producer.send(mess); } producer.close(); connection.start(); for (int i = 0; i < numMessages; i++) { Message m = messageConsumer.receive(5000); Assert.assertNotNull(m); } connection.close(); SimpleString qName = new SimpleString("test"); Wait.waitFor(() -> server.locateQueue(qName) == null); // ensure the topic was removed Assert.assertNull(server.locateQueue(qName)); // make sure the JMX control was removed for the JMS topic assertNull(server.getManagementService().getResource("jtest")); }
Example #27
Source File: FloodServerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void _testFlood() throws Exception { ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616?retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1&callTimeout=30000&clientFailureCheckPeriod=1000&maxRetryInterval=1000&blockOnDurableSend=false&blockOnAcknowledge=false", "cf"); final int numProducers = 20; final int numConsumers = 20; final int numMessages = 10000; ProducerThread[] producers = new ProducerThread[numProducers]; for (int i = 0; i < numProducers; i++) { producers[i] = new ProducerThread(cf, numMessages); } ConsumerThread[] consumers = new ConsumerThread[numConsumers]; for (int i = 0; i < numConsumers; i++) { consumers[i] = new ConsumerThread(cf, numMessages); } for (int i = 0; i < numConsumers; i++) { consumers[i].start(); } for (int i = 0; i < numProducers; i++) { producers[i].start(); } for (int i = 0; i < numConsumers; i++) { consumers[i].join(); } for (int i = 0; i < numProducers; i++) { producers[i].join(); } }
Example #28
Source File: ArtemisJmsTest.java From a with Apache License 2.0 | 5 votes |
@Override protected ConnectionFactory getConnectionFactory() { try { return ActiveMQJMSClient.createConnectionFactory(AMQ_ARTEMIS_URL, ""); }catch(Exception e){ e.printStackTrace(); return null; } }
Example #29
Source File: AutoCreateJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testAutoCreateOnSendToTopic() throws Exception { Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Topic topic = ActiveMQJMSClient.createTopic(QUEUE_NAME); MessageProducer producer = session.createProducer(topic); producer.send(session.createTextMessage("msg")); connection.close(); assertNotNull(server.getManagementService().getResource(ResourceNames.ADDRESS + "test")); }
Example #30
Source File: URITest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testParseURIs() throws Throwable { ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false", "some name"); Assert.assertEquals(2, ((ServerLocatorImpl) factory.getServerLocator()).getInitialConnectors().length); ActiveMQConnectionFactory factory2 = new ActiveMQConnectionFactory("(tcp://localhost:61614,tcp://localhost:61616)?blockOnDurableSend=false"); Assert.assertEquals(2, ((ServerLocatorImpl) factory2.getServerLocator()).getInitialConnectors().length); ServerLocator locator = ServerLocatorImpl.newLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false"); Assert.assertEquals(2, ((ServerLocatorImpl) locator).getInitialConnectors().length); ServerLocator locator2 = ActiveMQClient.createServerLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false"); Assert.assertEquals(2, ((ServerLocatorImpl) locator2).getInitialConnectors().length); }