Java Code Examples for org.apache.qpid.jms.JmsConnection#setClientID()
The following examples show how to use
org.apache.qpid.jms.JmsConnection#setClientID() .
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: IdleTimeoutIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testConnectionSetFailedWhenPeerNeglectsToSendEmptyFrames() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { int configuredTimeout = 200; testPeer.expectSaslAnonymous(); testPeer.expectOpen(); // Each connection creates a session for managing temporary destinations etc testPeer.expectBegin(); JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + "?amqp.idleTimeout=" + configuredTimeout); final JmsConnection connection = (JmsConnection) factory.createConnection(); // Set a clientID to provoke the actual AMQP connection process to occur. connection.setClientID("clientName"); testPeer.waitForAllHandlersToComplete(1000); // The peer is still connected, so it will get the close frame with error testPeer.expectClose(Matchers.notNullValue(), false); assertNull(testPeer.getThrowable()); testPeer.setSuppressReadExceptionOnClose(true); boolean failed = Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return connection.isFailed(); } }, 10000, 10); assertTrue("connection didnt fail in expected timeframe", failed); testPeer.waitForAllHandlersToComplete(1000); connection.close(); } }
Example 2
Source File: IdleTimeoutIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testConnectionNotMarkedFailedWhenPeerSendsEmptyFrames() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { int configuredTimeout = 2000; int period = 500; int cycles = 6; final CountDownLatch latch = new CountDownLatch(cycles); testPeer.expectSaslAnonymous(); testPeer.expectOpen(); // Each connection creates a session for managing temporary destinations etc testPeer.expectBegin(); // Start to emit idle frames when the connection is set up, this should stop it timing out testPeer.runAfterLastHandler(new EmptyFrameSender(latch, period, cycles, testPeer)); JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + "?amqp.idleTimeout=" + configuredTimeout); final JmsConnection connection = (JmsConnection) factory.createConnection(); // Set a clientID to provoke the actual AMQP connection process to occur. connection.setClientID("clientName"); boolean framesSent = latch.await(cycles * period * 2, TimeUnit.MILLISECONDS); assertTrue("idle frames were not sent as expected", framesSent); assertFalse("connection shouldnt fail", connection.isFailed()); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); assertNull(testPeer.getThrowable()); } }
Example 3
Source File: AMQPClient.java From amazon-mq-workshop with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { CommandLine cmd = parseAndValidateCommandLineArguments(args); final WrapInt count = new WrapInt(); final long ds = System.currentTimeMillis(); final int interval = Integer.parseInt(cmd.getOptionValue("interval", "1000")); String name = cmd.getOptionValue("name", UUID.randomUUID().toString()); int deliveryMode = cmd.hasOption("notPersistent") ? DeliveryMode.NON_PERSISTENT : DeliveryMode.PERSISTENT; registerShutdownHook(count, ds, interval); try { String user = null; String password = null; String secrets = null; if (cmd.hasOption("user") && cmd.hasOption("password")) { user = cmd.getOptionValue("user"); password = cmd.getOptionValue("password"); } else { secrets = getUserPassword("MQBrokerUserPassword"); if (secrets!=null && !secrets.isEmpty()) { user = secrets.split(",")[0]; password = secrets.split(",")[1]; } } JmsConnectionFactory connFact = new JmsConnectionFactory(user, password, cmd.getOptionValue("url")); JmsConnection conn = (JmsConnection) connFact.createConnection(); conn.setClientID("AmazonMQWorkshop-" + System.currentTimeMillis()); conn.start(); Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); if (cmd.getOptionValue("mode").contentEquals("sender")) { if (cmd.getOptionValue("type").contentEquals("queue")) { MessageProducer queueMessageProducer = session.createProducer(session.createQueue(cmd.getOptionValue("type") + "://" + cmd.getOptionValue("destination"))); sendMessages(session, queueMessageProducer, name, interval, deliveryMode, count); } else { MessageProducer topicMessageProducer = session.createProducer(session.createTopic(cmd.getOptionValue("type") + "://" + cmd.getOptionValue("destination"))); sendMessages(session, topicMessageProducer, name, interval, deliveryMode, count); } } else { if (cmd.getOptionValue("type").contentEquals("queue")) { MessageConsumer queueConsumer = session.createConsumer(session.createQueue(cmd.getOptionValue("destination"))); receiveMessages(session, queueConsumer); } else { MessageConsumer topicConsumer = session.createConsumer(session.createTopic(cmd.getOptionValue("destination"))); receiveMessages(session, topicConsumer); } } } catch (javax.jms.JMSSecurityException ex) { System.out.println(String.format("Error: %s", ex.getMessage())); System.exit(1); } }