ClientSession session; boolean isBlockOnAcknowledge = sessionFactory.getServerLocator().isBlockOnAcknowledge(); int ackBatchSize = sessionFactory.getServerLocator().getAckBatchSize(); if (acknowledgeMode == Session.SESSION_TRANSACTED) { session = sessionFactory.createSession(username, password, isXA, false, false, sessionFactory.getServerLocator().isPreAcknowledge(), transactionBatchSize);
void start() { log.info("Starting {}", this.getClass().getSimpleName()); try { sessionFactory = serverLocator.createSessionFactory(); session = sessionFactory.createSession(username, password, false, true, true, serverLocator.isPreAcknowledge(), serverLocator.getAckBatchSize()); } catch (RuntimeException runtimeEx) { throw runtimeEx; } catch (Exception ex) { throw new ActiveMQClientResourceException(String.format("%s initialisation failure", this.getClass().getSimpleName()), ex); } createClient(); try { session.start(); } catch (ActiveMQException amqEx) { throw new ActiveMQClientResourceException(String.format("%s startup failure", this.getClass().getSimpleName()), amqEx); } }
@Override protected ClientSession createSession(ClientSessionFactory sf, boolean autoCommitSends, boolean autoCommitAcks) throws Exception { return createSession(sf, autoCommitSends, autoCommitAcks, sf.getServerLocator().getAckBatchSize()); }
@Override protected ClientSession createSession(ClientSessionFactory sf, boolean xa, boolean autoCommitSends, boolean autoCommitAcks) throws Exception { return createSession(sf, xa, autoCommitSends, autoCommitAcks, sf.getServerLocator().getAckBatchSize()); }
@Override protected ClientSession createSession(ClientSessionFactory sf) throws Exception { return createSession(sf, true, true, sf.getServerLocator().getAckBatchSize()); }
@Test public void testDualAuthentication() throws Exception { String text = RandomUtil.randomString(); tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true); tc.getParams().put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, CLIENT_SIDE_TRUSTSTORE); tc.getParams().put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, PASSWORD); tc.getParams().put(TransportConstants.KEYSTORE_PATH_PROP_NAME, CLIENT_SIDE_KEYSTORE); tc.getParams().put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, PASSWORD); tc.getParams().put(TransportConstants.PORT_PROP_NAME, "61617"); ServerLocator producerLocator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc)); ClientSessionFactory producerSessionFactory = createSessionFactory(producerLocator); ClientSession producerSession = producerSessionFactory.createSession(false, true, true); producerSession.createQueue(DualAuthenticationTest.QUEUE, DualAuthenticationTest.QUEUE, false); ClientProducer producer = producerSession.createProducer(DualAuthenticationTest.QUEUE); ClientMessage message = createTextMessage(producerSession, text); producer.send(message); ServerLocator consumerLocator = addServerLocator(ActiveMQClient.createServerLocator("tcp://localhost:61616")); ClientSessionFactory consumerSessionFactory = createSessionFactory(consumerLocator); ClientSession consumerSession = consumerSessionFactory.createSession("consumer", "consumerPassword", false, true, true, consumerLocator.isPreAcknowledge(), consumerLocator.getAckBatchSize()); ClientConsumer consumer = consumerSession.createConsumer(DualAuthenticationTest.QUEUE); consumerSession.start(); Message m = consumer.receive(1000); Assert.assertNotNull(m); Assert.assertEquals(text, m.getBodyBuffer().readString()); }
ClientSession session; boolean isBlockOnAcknowledge = sessionFactory.getServerLocator().isBlockOnAcknowledge(); int ackBatchSize = sessionFactory.getServerLocator().getAckBatchSize(); if (acknowledgeMode == Session.SESSION_TRANSACTED) { session = sessionFactory.createSession(username, password, isXA, false, false, sessionFactory.getServerLocator().isPreAcknowledge(), transactionBatchSize);
ClientSession session; boolean isBlockOnAcknowledge = sessionFactory.getServerLocator().isBlockOnAcknowledge(); int ackBatchSize = sessionFactory.getServerLocator().getAckBatchSize(); if (acknowledgeMode == Session.SESSION_TRANSACTED) { session = sessionFactory.createSession(username, password, isXA, false, false, sessionFactory.getServerLocator().isPreAcknowledge(), transactionBatchSize);
ClientSession session; boolean isBlockOnAcknowledge = sessionFactory.getServerLocator().isBlockOnAcknowledge(); int ackBatchSize = sessionFactory.getServerLocator().getAckBatchSize(); if (acknowledgeMode == Session.SESSION_TRANSACTED) { session = sessionFactory.createSession(username, password, isXA, false, false, sessionFactory.getServerLocator().isPreAcknowledge(), transactionBatchSize);
ClientSession session; boolean isBlockOnAcknowledge = sessionFactory.getServerLocator().isBlockOnAcknowledge(); int ackBatchSize = sessionFactory.getServerLocator().getAckBatchSize(); if (acknowledgeMode == Session.SESSION_TRANSACTED) { session = sessionFactory.createSession(username, password, isXA, false, false, sessionFactory.getServerLocator().isPreAcknowledge(), transactionBatchSize);
@Test public void testConnectionCreatedAndDestroyed() throws Exception { NotificationTest.flush(notifConsumer); ClientSessionFactory sf = createSessionFactory(locator); ClientSession mySession = sf.createSession("myUser", "myPassword", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize()); mySession.start(); ClientMessage[] notifications = NotificationTest.consumeMessages(2, notifConsumer); Assert.assertEquals(CONNECTION_CREATED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertNotNull(notifications[0].getObjectProperty(ManagementHelper.HDR_CONNECTION_NAME)); final String connectionId = notifications[0].getObjectProperty(ManagementHelper.HDR_CONNECTION_NAME).toString(); Assert.assertEquals(SESSION_CREATED.toString(), notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertNotNull(notifications[1].getObjectProperty(ManagementHelper.HDR_CONNECTION_NAME)); Assert.assertNotNull(notifications[1].getObjectProperty(ManagementHelper.HDR_SESSION_NAME)); Assert.assertEquals(SimpleString.toSimpleString("myUser"), notifications[1].getObjectProperty(ManagementHelper.HDR_USER)); NotificationTest.flush(notifConsumer); mySession.close(); sf.close(); notifications = NotificationTest.consumeMessages(2, notifConsumer); Assert.assertEquals(SESSION_CLOSED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertNotNull(notifications[0].getObjectProperty(ManagementHelper.HDR_CONNECTION_NAME)); Assert.assertNotNull(notifications[0].getObjectProperty(ManagementHelper.HDR_SESSION_NAME)); Assert.assertEquals(SimpleString.toSimpleString("myUser"), notifications[0].getObjectProperty(ManagementHelper.HDR_USER)); Assert.assertEquals(CONNECTION_DESTROYED.toString(), notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertNotNull(notifications[1].getObjectProperty(ManagementHelper.HDR_CONNECTION_NAME)); Assert.assertEquals(connectionId, notifications[1].getObjectProperty(ManagementHelper.HDR_CONNECTION_NAME).toString()); }
@Test public void testCONSUMER_CLOSED() throws Exception { ClientSessionFactory sf = createSessionFactory(locator); ClientSession mySession = sf.createSession("myUser", "myPassword", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize()); mySession.start(); SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); boolean durable = RandomUtil.randomBoolean(); mySession.createQueue(address, queue, durable); ClientConsumer consumer = mySession.createConsumer(queue); SimpleString sessionName = SimpleString.toSimpleString(((ClientSessionInternal) mySession).getName()); NotificationTest.flush(notifConsumer); consumer.close(); ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer); Assert.assertEquals(CONSUMER_CLOSED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertEquals(queue.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString()); Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString()); Assert.assertEquals(0, notifications[0].getObjectProperty(ManagementHelper.HDR_CONSUMER_COUNT)); Assert.assertEquals(SimpleString.toSimpleString("myUser"), notifications[0].getSimpleStringProperty(ManagementHelper.HDR_USER)); Assert.assertEquals(SimpleString.toSimpleString("invm:0"), notifications[0].getSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS)); Assert.assertEquals(sessionName, notifications[0].getSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME)); session.deleteQueue(queue); }
@Test public void testCONSUMER_CREATED() throws Exception { ClientSessionFactory sf = createSessionFactory(locator); ClientSession mySession = sf.createSession("myUser", "myPassword", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize()); mySession.start(); SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); boolean durable = RandomUtil.randomBoolean(); session.createQueue(address, queue, durable); NotificationTest.flush(notifConsumer); ClientConsumer consumer = mySession.createConsumer(queue); SimpleString consumerName = SimpleString.toSimpleString(((ClientSessionInternal) mySession).getName()); ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer); Assert.assertEquals(CONSUMER_CREATED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertEquals(queue.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString()); Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString()); Assert.assertEquals(1, notifications[0].getObjectProperty(ManagementHelper.HDR_CONSUMER_COUNT)); Assert.assertEquals(SimpleString.toSimpleString("myUser"), notifications[0].getSimpleStringProperty(ManagementHelper.HDR_USER)); Assert.assertEquals(null, notifications[0].getSimpleStringProperty(ManagementHelper.HDR_VALIDATED_USER)); Assert.assertEquals(SimpleString.toSimpleString("invm:0"), notifications[0].getSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS)); Assert.assertEquals(consumerName, notifications[0].getSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME)); Assert.assertEquals(SimpleString.toSimpleString("unavailable"), notifications[0].getSimpleStringProperty(ManagementHelper.HDR_CERT_SUBJECT_DN)); consumer.close(); session.deleteQueue(queue); }
@Test public void testMessageExpired() throws Exception { ClientSessionFactory sf = createSessionFactory(locator); ClientSession mySession = sf.createSession("myUser", "myPassword", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize()); mySession.start(); SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); boolean durable = RandomUtil.randomBoolean(); session.createQueue(address, queue, durable); ClientConsumer consumer = mySession.createConsumer(queue); ClientProducer producer = mySession.createProducer(address); NotificationTest.flush(notifConsumer); ClientMessage msg = session.createMessage(false); msg.putStringProperty("someKey", "someValue"); msg.setExpiration(1); producer.send(msg); Thread.sleep(500); consumer.receive(500); ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer); Assert.assertEquals(MESSAGE_EXPIRED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertNotNull(notifications[0].getObjectProperty(ManagementHelper.HDR_MESSAGE_ID)); Assert.assertEquals(address, notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS)); Assert.assertEquals(queue, notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME)); Assert.assertEquals(RoutingType.MULTICAST.getType(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_TYPE)); consumer.close(); session.deleteQueue(queue); }
@Test public void testMessageDelivered() throws Exception { ClientSessionFactory sf = createSessionFactory(locator); ClientSession mySession = sf.createSession("myUser", "myPassword", false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize()); mySession.start(); SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); boolean durable = RandomUtil.randomBoolean(); session.createQueue(address, queue, durable); ClientConsumer consumer = mySession.createConsumer(queue); ClientProducer producer = mySession.createProducer(address); NotificationTest.flush(notifConsumer); ClientMessage msg = session.createMessage(false); msg.putStringProperty("someKey", "someValue"); producer.send(msg); consumer.receive(1000); ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer); Assert.assertEquals(MESSAGE_DELIVERED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertNotNull(notifications[0].getObjectProperty(ManagementHelper.HDR_MESSAGE_ID)); Assert.assertNotNull(notifications[0].getObjectProperty(ManagementHelper.HDR_CONSUMER_NAME)); Assert.assertEquals(address, notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS)); Assert.assertEquals(queue, notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME)); Assert.assertEquals(RoutingType.MULTICAST.getType(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_TYPE)); consumer.close(); session.deleteQueue(queue); }
Assert.assertEquals(locator.isPreAcknowledge(), preAcknowledge); Assert.assertEquals(locator.getConnectionLoadBalancingPolicyClassName(), loadBalancingPolicyClassName); Assert.assertEquals(locator.getAckBatchSize(), ackBatchSize); Assert.assertEquals(locator.isUseGlobalPools(), useGlobalPools); Assert.assertEquals(locator.getScheduledThreadPoolMaxSize(), scheduledThreadPoolMaxSize);
Assert.assertEquals(preAcknowledge, locator.isPreAcknowledge()); Assert.assertEquals(loadBalancingPolicyClassName, locator.getConnectionLoadBalancingPolicyClassName()); Assert.assertEquals(ackBatchSize, locator.getAckBatchSize()); Assert.assertEquals(useGlobalPools, locator.isUseGlobalPools()); Assert.assertEquals(scheduledThreadPoolMaxSize, locator.getScheduledThreadPoolMaxSize());
cf.getServerLocator().isPreAcknowledge(); cf.getServerLocator().getConnectionLoadBalancingPolicyClassName(); cf.getServerLocator().getAckBatchSize(); cf.getServerLocator().isUseGlobalPools(); cf.getServerLocator().getScheduledThreadPoolMaxSize();