org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory Java Examples
The following examples show how to use
org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.
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: SecurityTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Login with valid user and password * But try send to address not authorised - Persistent * Should not allow and should throw exception */ @Test public void testLoginValidUserAndPasswordButNotAuthorisedToSend() throws Exception { SimpleString queueName = SimpleString.toSimpleString("guest.cannot.send"); if (getJmsServer().locateQueue(queueName) == null) { getJmsServer().createQueue(new QueueConfiguration(queueName).setRoutingType(RoutingType.ANYCAST)); } ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = connectionFactory.createConnection("guest", "guest"); Session session = connection.createSession(); Destination destination = session.createQueue(queueName.toString()); MessageProducer messageProducer = session.createProducer(destination); try { messageProducer.send(session.createTextMessage("hello")); fail("JMSSecurityException expected as guest is not allowed to send"); } catch (JMSSecurityException activeMQSecurityException) { //pass } connection.close(); }
Example #2
Source File: AddressQueryTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testAddressQueryDefaultsOnAutoCreatedAddress() throws Exception { SimpleString addressName = SimpleString.toSimpleString(UUID.randomUUID().toString()); server.getAddressSettingsRepository().addMatch(addressName.toString(), new AddressSettings()); ConnectionFactory cf = new ActiveMQConnectionFactory("vm://0"); JMSContext c = cf.createContext(); c.createProducer().send(c.createTopic(addressName.toString()), c.createMessage()); AddressQueryResult addressQueryResult = server.addressQuery(addressName); assertTrue(addressQueryResult.isExists()); assertFalse(addressQueryResult.getRoutingTypes().contains(RoutingType.ANYCAST)); assertTrue(addressQueryResult.getRoutingTypes().contains(RoutingType.MULTICAST)); assertEquals(addressName, addressQueryResult.getName()); assertTrue(addressQueryResult.isAutoCreateAddresses()); assertEquals(-1, addressQueryResult.getDefaultMaxConsumers()); assertTrue(addressQueryResult.isAutoCreated()); assertFalse(addressQueryResult.isDefaultPurgeOnNoConsumers()); }
Example #3
Source File: BrokerConsumerThread.java From OpenIoE with Apache License 2.0 | 6 votes |
public void StartBrokerConsumer() throws JMSException { // ApplicationContext context = new AnnotationConfigApplicationContext(IoeConfiguration.class); // IoeConfiguration ioeConfiguration = context.getBean(IoeConfiguration.class); 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); List<Subscription> subscriptions = subscriptionRepository.findAll(); for(Subscription s:subscriptions) { Topic topic = ActiveMQJMSClient.createTopic(s.getTopicFilter()); MessageConsumer messageConsumer = session.createConsumer(topic); messageConsumer.setMessageListener(new BrokerMessageListener(sensorRepository, databaseService)); } connection.start(); } catch (Exception ex) { ex.printStackTrace(); } }
Example #4
Source File: SimpleJNDIClientTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testRemoteCFWithJgroupsWithTransportConfigFile() throws Exception { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory.class.getCanonicalName()); props.put("connectionFactory.myConnectionFactory", "jgroups://testChannelName?file=test-jgroups-file_ping.xml&" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration(); Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout()); Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()); BroadcastEndpoint broadcastEndpoint = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory().createBroadcastEndpoint(); Assert.assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpoint); broadcastEndpoint.close(false); }
Example #5
Source File: ConnectionTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testTwoConnectionsSameIDThroughCF() throws Exception { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?clientID=myid"); conn = connectionFactory.createConnection(); try { conn2 = connectionFactory.createConnection(); Assert.fail("Exception expected"); } catch (InvalidClientIDException expected) { // expected } Session session1 = conn.createSession(); Session session2 = conn.createSession(); session1.close(); session2.close(); }
Example #6
Source File: ActiveMQArtemisConnectionFactoryCreator.java From yaks with Apache License 2.0 | 6 votes |
@Override public ConnectionFactory create(Map<String, String> properties) { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); try { if (properties.containsKey("brokerUrl")) { connectionFactory.setBrokerURL(properties.get("brokerUrl")); } if (properties.containsKey("username")) { connectionFactory.setUser(properties.get("username")); } if (properties.containsKey("password")) { connectionFactory.setPassword(properties.get("password")); } } catch (JMSException e) { throw new IllegalStateException("Error in initialization ConnectionFactory", e); } return connectionFactory; }
Example #7
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 #8
Source File: TCPSchema.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override protected ActiveMQConnectionFactory internalNewObject(URI uri, Map<String, String> query, String name) throws Exception { JMSConnectionOptions options = newConectionOptions(uri, query); List<TransportConfiguration> configurations = TCPTransportConfigurationSchema.getTransportConfigurations(uri, query, TransportConstants.ALLOWABLE_CONNECTOR_KEYS, name, NettyConnectorFactory.class.getName()); TransportConfiguration[] tcs = new TransportConfiguration[configurations.size()]; configurations.toArray(tcs); ActiveMQConnectionFactory factory; if (options.isHa()) { factory = ActiveMQJMSClient.createConnectionFactoryWithHA(options.getFactoryTypeEnum(), tcs); } else { factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), tcs); } setData(uri, query, factory); checkIgnoredQueryFields(factory, query); return factory; }
Example #9
Source File: JMSContextExample.java From activemq-artemis with Apache License 2.0 | 6 votes |
public static void main(final String[] args) throws Exception { // Instantiate the queue Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); // Instantiate the ConnectionFactory (Using the default URI on this case) // Also instantiate the jmsContext // Using closeable interface try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); JMSContext jmsContext = cf.createContext()) { // Create a message producer, note that we can chain all this into one statement jmsContext.createProducer().setDeliveryMode(DeliveryMode.PERSISTENT).send(queue, "this is a string"); // Create a Consumer and receive the payload of the message direct. String payLoad = jmsContext.createConsumer(queue).receiveBody(String.class); System.out.println("payLoad = " + payLoad); } }
Example #10
Source File: JournalPendingMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testQueueLargeMessageSize() throws Exception { ActiveMQConnectionFactory acf = (ActiveMQConnectionFactory) cf; acf.setMinLargeMessageSize(1000); Connection connection = cf.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String testText = StringUtils.repeat("t", 5000); ActiveMQTextMessage message = (ActiveMQTextMessage) session.createTextMessage(testText); session.createProducer(session.createQueue(defaultQueueName)).send(message); verifyPendingStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize()); verifyPendingDurableStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize()); connection.close(); this.killServer(); this.restartServer(); verifyPendingStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize()); verifyPendingDurableStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize()); }
Example #11
Source File: ResourceAdapterTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testResourceAdapterSetupReconnectAttemptDefault() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); qResourceAdapter.setConnectionParameters("server-id=0"); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); assertEquals(-1, fac.getReconnectAttempts()); qResourceAdapter.stop(); assertFalse(spec.isHasBeenUpdated()); }
Example #12
Source File: ResourceAdapterTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testResourceAdapterSetupNoReconnectAttemptsOverride() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); qResourceAdapter.setConnectionParameters("server-id=0"); qResourceAdapter.setReconnectAttempts(100); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); assertEquals(100, fac.getReconnectAttempts()); qResourceAdapter.stop(); assertFalse(spec.isHasBeenUpdated()); }
Example #13
Source File: JMSServerManagerImpl.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public boolean addConnectionFactoryToBindingRegistry(final String name, final String registryBinding) throws Exception { checkInitialised(); checkBindings(registryBinding); ActiveMQConnectionFactory factory = connectionFactories.get(name); if (factory == null) { throw new IllegalArgumentException("Factory does not exist"); } if (registry.lookup(registryBinding) != null) { throw ActiveMQJMSServerBundle.BUNDLE.cfBindingsExists(name); } boolean added = bindToBindings(registryBinding, factory); if (added) { addToBindings(connectionFactoryBindings, name, registryBinding); storage.addBindings(PersistedType.ConnectionFactory, name, registryBinding); } return added; }
Example #14
Source File: AddressQueryTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testAddressQueryNonDefaultsOnAutoCreatedAddress() throws Exception { SimpleString addressName = SimpleString.toSimpleString(UUID.randomUUID().toString()); server.getAddressSettingsRepository().addMatch(addressName.toString(), new AddressSettings().setAutoCreateAddresses(true).setDefaultMaxConsumers(1).setDefaultPurgeOnNoConsumers(true)); ConnectionFactory cf = new ActiveMQConnectionFactory("vm://0"); JMSContext c = cf.createContext(); c.createProducer().send(c.createTopic(addressName.toString()), c.createMessage()); AddressQueryResult addressQueryResult = server.addressQuery(addressName); assertTrue(addressQueryResult.isExists()); assertTrue(addressQueryResult.getRoutingTypes().contains(RoutingType.MULTICAST)); assertEquals(addressName, addressQueryResult.getName()); assertTrue(addressQueryResult.isAutoCreateAddresses()); assertEquals(1, addressQueryResult.getDefaultMaxConsumers()); assertTrue(addressQueryResult.isAutoCreated()); assertTrue(addressQueryResult.isDefaultPurgeOnNoConsumers()); }
Example #15
Source File: ObjectFactoryTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testJndiSslParameters() throws Exception { Reference reference = new Reference(ActiveMQConnectionFactory.class.getName(), JNDIReferenceFactory.class.getName(), null); reference.add(new StringRefAddr("brokerURL", "(tcp://localhost:61616,tcp://localhost:5545,tcp://localhost:5555)?sslEnabled=false&trustStorePath=nopath")); reference.add(new StringRefAddr(TransportConstants.SSL_ENABLED_PROP_NAME, "true")); reference.add(new StringRefAddr(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "/path/to/trustStore")); reference.add(new StringRefAddr(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "trustStorePassword")); reference.add(new StringRefAddr(TransportConstants.KEYSTORE_PATH_PROP_NAME, "/path/to/keyStore")); reference.add(new StringRefAddr(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "keyStorePassword")); reference.add(new StringRefAddr("doesnotexist", "somevalue")); JNDIReferenceFactory referenceFactory = new JNDIReferenceFactory(); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory)referenceFactory.getObjectInstance(reference, null, null, null); URI uri = cf.toURI(); Map<String, String> params = URISupport.parseParameters(uri); Assert.assertEquals("true", params.get(TransportConstants.SSL_ENABLED_PROP_NAME)); Assert.assertEquals("/path/to/trustStore", params.get(TransportConstants.TRUSTSTORE_PATH_PROP_NAME)); Assert.assertEquals("trustStorePassword", params.get(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME)); Assert.assertEquals("/path/to/keyStore", params.get(TransportConstants.KEYSTORE_PATH_PROP_NAME)); Assert.assertEquals("keyStorePassword", params.get(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME)); Assert.assertNull(params.get("doesnotexist")); }
Example #16
Source File: ServerUtil.java From activemq-artemis with Apache License 2.0 | 6 votes |
public static boolean waitForServerToStart(String uri, long timeout) throws InterruptedException { long realTimeout = System.currentTimeMillis() + timeout; while (System.currentTimeMillis() < realTimeout) { try (ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory(uri, null)) { cf.createConnection().close(); System.out.println("server " + uri + " started"); } catch (Exception e) { System.out.println("awaiting server " + uri + " start at "); Thread.sleep(500); continue; } return true; } return false; }
Example #17
Source File: ResourceAdapterTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testResourceAdapterSetupNoHAOverride() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); qResourceAdapter.setConnectionParameters("server-id=0"); qResourceAdapter.setHA(true); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); assertTrue(fac.isHA()); qResourceAdapter.stop(); assertFalse(spec.isHasBeenUpdated()); }
Example #18
Source File: SimpleJNDIClientTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testRemoteCFWithJgroupsWithTransportConfigNullProps() throws Exception { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); props.put("connectionFactory.ConnectionFactory", "jgroups://testChannelName?" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("ConnectionFactory"); DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration(); Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout()); Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()); BroadcastEndpointFactory broadcastEndpointFactory = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory(); Assert.assertTrue(broadcastEndpointFactory instanceof JGroupsPropertiesBroadcastEndpointFactory); JGroupsPropertiesBroadcastEndpointFactory endpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) broadcastEndpointFactory; Assert.assertEquals(endpointFactory.getProperties(), null); Assert.assertEquals(endpointFactory.getChannelName(), "testChannelName"); }
Example #19
Source File: ActiveMQConnectionFactoryTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testDefaultConstructor() throws Exception { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF); assertFactoryParams(cf, null, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); Connection conn = null; try { conn = cf.createConnection(); conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Assert.fail("Should throw exception"); } catch (JMSException e) { // Ok } if (conn != null) { conn.close(); } testSettersThrowException(cf); }
Example #20
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 #21
Source File: SecurityTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Login with valid user and invalid password * Should allow */ @Test public void testLoginValidUserInvalidPasswordSystemProperty() throws Exception { System.setProperty(DefaultConnectionProperties.AMQ_USER, "guest"); System.setProperty(DefaultConnectionProperties.AMQ_PASSWORD, "not.the.valid.password"); DefaultConnectionProperties.initialize(); try { ConnectionFactory cf = new ActiveMQConnectionFactory(); Connection conn1 = addConnection(cf.createConnection()); ProxyAssertSupport.fail(); } catch (JMSSecurityException e) { // Expected } }
Example #22
Source File: MessageSerializerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void internalTestSendDirectToQueue(RoutingType routingType) throws Exception { String address = "test"; String queue1Name = "queue1"; String queue2Name = "queue2"; createQueue(routingType, address, queue1Name); createQueue(routingType, address, queue2Name); try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = cf.createConnection("admin", "admin");) { // send messages to queue Session session = createSession(connection); Destination queue1 = session.createQueue(CompositeAddress.toFullyQualified(address, queue1Name)); Destination queue2 = session.createQueue(CompositeAddress.toFullyQualified(address, queue2Name)); MessageConsumer consumer1 = session.createConsumer(queue1); MessageConsumer consumer2 = session.createConsumer(queue2); new Producer() .setDestination((routingType == RoutingType.ANYCAST ? ActiveMQDestination.QUEUE_QUALIFIED_PREFIX : ActiveMQDestination.TOPIC_QUALIFIED_PREFIX) + CompositeAddress.toFullyQualified(address, queue1Name)) .setMessageCount(5) .setUser("admin") .setPassword("admin") .execute(new TestActionContext()); assertNull(consumer2.receive(1000)); assertNotNull(consumer1.receive(1000)); } }
Example #23
Source File: ConnectionFactoryURITest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testUDPAllProperties() throws Exception { StringBuilder sb = new StringBuilder(); sb.append("udp://localhost:3030?ha=true"); BeanUtilsBean bean = new BeanUtilsBean(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(true, (TransportConfiguration) null); populate(sb, bean, factory); ActiveMQConnectionFactory factory2 = parser.newObject(new URI(sb.toString()), null); checkEquals(bean, factory, factory2); }
Example #24
Source File: JmsConsumerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testBrowserOnly() throws Exception { ((ActiveMQConnectionFactory) cf).setConsumerWindowSize(0); conn = cf.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME); MessageProducer producer = session.createProducer(jBossQueue); int noOfMessages = 10; for (int i = 0; i < noOfMessages; i++) { TextMessage textMessage = session.createTextMessage("m" + i); textMessage.setIntProperty("i", i); producer.send(textMessage); } QueueBrowser browser = session.createBrowser(jBossQueue); Enumeration enumMessages = browser.getEnumeration(); for (int i = 0; i < noOfMessages; i++) { Assert.assertTrue(enumMessages.hasMoreElements()); TextMessage msg = (TextMessage) enumMessages.nextElement(); Assert.assertNotNull(msg); Assert.assertEquals(i, msg.getIntProperty("i")); } Assert.assertFalse(enumMessages.hasMoreElements()); conn.close(); // 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 #25
Source File: RemoteBindingWithoutLoadBalancingTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testStackOverflowJMS() throws Exception { final String QUEUE_NAME = "queues.queue0"; setupCluster(); startServers(); ConnectionFactory cf1 = new ActiveMQConnectionFactory("vm://0"); Connection c1 = cf1.createConnection(); c1.start(); Session s1 = c1.createSession(); MessageConsumer mc1 = s1.createConsumer(s1.createQueue(QUEUE_NAME)); waitForBindings(0, QUEUE_NAME, 1, 1, true); waitForBindings(1, QUEUE_NAME, 1, 1, false); ConnectionFactory cf2 = new ActiveMQConnectionFactory("vm://1"); Connection c2 = cf2.createConnection(); Session s2 = c2.createSession(); MessageProducer mp2 = s2.createProducer(s2.createQueue(QUEUE_NAME)); mp2.send(s2.createMessage()); waitForBindings(1, QUEUE_NAME, 1, 0, true); assertTrue(Wait.waitFor(() -> servers[1].locateQueue(SimpleString.toSimpleString(QUEUE_NAME)).getMessageCount() == 1, 2000, 100)); c1.close(); c2.close(); }
Example #26
Source File: SimpleJNDIClientTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testRemoteCFWithJGroups() throws Exception { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); props.put("connectionFactory.myConnectionFactory", "jgroups://mychannelid?file=test-jgroups-file_ping.xml"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); connectionFactory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory().createBroadcastEndpoint().close(false); }
Example #27
Source File: JMSFailoverTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testCreateQueue() throws Exception { liveJMSServer.createQueue(true, "queue1", null, true, "/queue/queue1"); assertNotNull(ctx1.lookup("/queue/queue1")); ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc); jbcf.setReconnectAttempts(-1); Connection conn = null; try { conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); JMSUtil.crash(liveServer, coreSession); assertNotNull(ctx2.lookup("/queue/queue1")); } finally { if (conn != null) { conn.close(); } } }
Example #28
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); }
Example #29
Source File: ActiveMQResourceAdapter.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Stop */ @Override public void stop() { if (logger.isTraceEnabled()) { logger.trace("stop()"); } for (Map.Entry<ActivationSpec, ActiveMQActivation> entry : activations.entrySet()) { try { entry.getValue().stop(); } catch (Exception ignored) { ActiveMQRALogger.LOGGER.debug("Ignored", ignored); } } activations.clear(); for (ActiveMQRAManagedConnectionFactory managedConnectionFactory : managedConnectionFactories) { managedConnectionFactory.stop(); } managedConnectionFactories.clear(); for (Pair<ActiveMQConnectionFactory, AtomicInteger> pair : knownConnectionFactories.values()) { pair.getA().close(); } knownConnectionFactories.clear(); if (defaultActiveMQConnectionFactory != null) { defaultActiveMQConnectionFactory.close(); } if (recoveryActiveMQConnectionFactory != null) { recoveryActiveMQConnectionFactory.close(); } recoveryManager.stop(); ActiveMQRALogger.LOGGER.raStopped(); }
Example #30
Source File: ActiveMQConnectionFactoryTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void sendObjectMessage(String qname, Serializable obj) throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://0"); Connection connection = factory.createConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue q = session.createQueue(qname); MessageProducer producer = session.createProducer(q); ObjectMessage objMessage = session.createObjectMessage(); objMessage.setObject(obj); producer.send(objMessage); } finally { connection.close(); } }