/** * Sends a message to the request address and wait for the given timeout for a reply. * The temporary queue is used for the REPLYTO_HEADER_NAME, and only one reply per request is expected * * @param request the message to send * @param timeout the timeout to wait for a reply (in milliseconds) * @return the reply message or {@code null} if no message is replied before the timeout elapses * @throws Exception */ public ClientMessage request(final ClientMessage request, final long timeout) throws Exception { request.putStringProperty(ClientMessageImpl.REPLYTO_HEADER_NAME, replyQueue); requestProducer.send(request); return replyConsumer.receive(timeout); }
/** * Closes the ClientRequestor and its session. * * @throws Exception if an exception occurs while closing the ClientRequestor */ @Override public void close() throws Exception { replyConsumer.close(); requestProducer.close(); queueSession.deleteQueue(replyQueue); }
private void checkClosed() throws JMSException { if (clientProducer.isClosed() || clientSession.isClosed()) { throw new IllegalStateException("Producer is closed"); } }
/** * @throws ActiveMQException */ private void sendMessages(int msgs) throws ActiveMQException { ClientProducer producer = prodSession.createProducer(ADDRESS); for (int i = 0; i < msgs; i++) { ClientMessage message = prodSession.createMessage(true); message.putIntProperty("prodNR", i % nThreads); producer.send(message); if (i % 100 == 0) { prodSession.commit(); } } prodSession.commit(); producer.close(); } }
@Test public void testCanNotUseAClosedProducer() throws Exception { final ClientProducer producer = session.createProducer(RandomUtil.randomSimpleString()); Assert.assertFalse(producer.isClosed()); producer.close(); Assert.assertTrue(producer.isClosed()); ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() { @Override public void run() throws ActiveMQException { producer.send(session.createMessage(false)); } }); }
/** * Send a ClientMessage to the server * * @param message the message to send */ public void sendMessage(ClientMessage message) { try { producer.send(message); } catch (ActiveMQException amqEx) { throw new ActiveMQClientResourceException(String.format("Failed to send message to %s", producer.getAddress().toString()), amqEx); } }
@Test public void testCreateProducer1() throws Exception { ClientProducer producer = clientSession.createProducer("testAddress"); Assert.assertNotNull(producer.getAddress()); Assert.assertEquals(cf.getServerLocator().getProducerMaxRate(), producer.getMaxRate()); Assert.assertEquals(cf.getServerLocator().isBlockOnNonDurableSend(), producer.isBlockOnNonDurableSend()); Assert.assertEquals(cf.getServerLocator().isBlockOnDurableSend(), producer.isBlockOnDurableSend()); Assert.assertFalse(producer.isClosed()); }
/** * Send a ClientMessage to the server * * @param message the message to send */ public void sendMessage(ClientMessage message) { try { producer.send(message); } catch (ActiveMQException amqEx) { throw new ActiveMQClientResourceException(String.format("Failed to send message to %s", producer.getAddress().toString()), amqEx); } }
@Test public void testCreateAnonProducer() throws Exception { ClientProducer producer = clientSession.createProducer(); Assert.assertNull(producer.getAddress()); Assert.assertEquals(cf.getServerLocator().getProducerMaxRate(), producer.getMaxRate()); Assert.assertEquals(cf.getServerLocator().isBlockOnNonDurableSend(), producer.isBlockOnNonDurableSend()); Assert.assertEquals(cf.getServerLocator().isBlockOnDurableSend(), producer.isBlockOnDurableSend()); Assert.assertFalse(producer.isClosed()); }
@Override public void close() throws JMSException { connection.getThreadAwareContext().assertNotCompletionListenerThread(); try { clientProducer.close(); } catch (ActiveMQException e) { throw JMSExceptionHelper.convertFromActiveMQException(e); } }
private void checkClosed() throws JMSException { if (clientProducer.isClosed()) { throw new IllegalStateException("Producer is closed"); } session.checkClosed(); }
@Override public Object call() throws ActiveMQException { producer.send(message); return null; } };
private void closeChildren() throws ActiveMQException { Set<ClientConsumerInternal> consumersClone = cloneConsumers(); for (ClientConsumer consumer : consumersClone) { consumer.close(); } Set<ClientProducerInternal> producersClone = cloneProducers(); for (ClientProducer producer : producersClone) { producer.close(); } }
private void checkClosed() throws JMSException { if (clientProducer.isClosed()) { throw new IllegalStateException("Producer is closed"); } session.checkClosed(); }
@Override protected void doWork(int count) throws Exception { if (count < messages) { ClientMessage m = createTextMessage(session, "msg" + count); producer.send(m); logger.debug("producer sent a message " + count); } else { this.working = false; } }
@Override protected void stopClient() { if (producer != null) { try { producer.close(); } catch (ActiveMQException amqEx) { log.warn("ActiveMQException encountered closing InternalClient ClientProducer - ignoring", amqEx); } finally { producer = null; } } }
private void checkClosed() throws JMSException { if (clientProducer.isClosed() || clientSession.isClosed()) { throw new IllegalStateException("Producer is closed"); } }
public void sendMessage(SimpleString address, ClientMessage message) { checkSession(); if (producer == null) { throw new IllegalStateException("ClientProducer is null - has the InternalClient been started?"); } try { producer.send(address, message); } catch (ActiveMQException amqEx) { throw new EmbeddedActiveMQResourceException(String.format("Failed to send message to %s", address.toString()), amqEx); } }
@Override protected void stopClient() { if (producer != null) { try { producer.close(); } catch (ActiveMQException amqEx) { log.warn("ActiveMQException encountered closing InternalClient ClientProducer - ignoring", amqEx); } finally { producer = null; } } }