Java Code Examples for javax.jms.Queue#getQueueName()
The following examples show how to use
javax.jms.Queue#getQueueName() .
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: JmsInstrumentationIT.java From apm-agent-java with Apache License 2.0 | 5 votes |
private void testQueueSendListen(Queue queue, Function<Destination, CompletableFuture<Message>> listenerRegistrationFunction) throws Exception { CompletableFuture<Message> incomingMessageFuture = listenerRegistrationFunction.apply(queue); String message = UUID.randomUUID().toString(); TextMessage outgoingMessage = brokerFacade.createTextMessage(message); brokerFacade.send(queue, outgoingMessage, false); Message incomingMessage = incomingMessageFuture.get(3, TimeUnit.SECONDS); verifyMessage(message, incomingMessage); String queueName = queue.getQueueName(); // special handling for temp queues if (queue instanceof TemporaryQueue || queueName.startsWith(TIBCO_TMP_QUEUE_PREFIX)) { queueName = TEMP; } verifySendListenOnNonTracedThread(queueName, outgoingMessage, 1); }
Example 2
Source File: VirtualTopicMappingExample.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static void main(final String[] args) throws Exception { Connection connection = null; try { ConnectionFactory cf = new ActiveMQConnectionFactory(); connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); //create consumer on queue that is used by the Virtual Topic Queue queue = session.createQueue("Consumer.A.VirtualTopic.Orders"); MessageConsumer messageConsumer = session.createConsumer(queue); connection.start(); //send message to virtual topic Topic topic = session.createTopic("VirtualTopic.Orders"); MessageProducer producer = session.createProducer(topic); TextMessage message = session.createTextMessage("This is a text message"); producer.send(message); System.out.println("Sent message with ID: " + message.getJMSMessageID() + " to Topic: " + topic.getTopicName()); //consume the message from the backing queue TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); if (messageReceived != null) { System.out.println("Received message with ID: " + messageReceived.getJMSMessageID() + " from Queue: " + queue.getQueueName()); } else { //unexpected outcome throw new RuntimeException("EXAMPLE FAILED - No message received from Queue: " + queue.getQueueName()); } } finally { if (connection != null) { connection.close(); } } }
Example 3
Source File: TempQueueWithDotTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void testSimple(String protocol) throws Exception { ConnectionFactory factory = CFUtil.createConnectionFactory(protocol, getConnectionUrl()); Connection connection = factory.createConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue dest = session.createTemporaryQueue(); String queueName = dest.getQueueName(); Wait.waitFor(() -> server.locateQueue(queueName) != null); org.apache.activemq.artemis.core.server.Queue queue = server.locateQueue(queueName); MessageConsumer consumer = null; try { consumer = session.createConsumer(dest); } catch (Exception e) { e.printStackTrace(); // I'm calling fail because openwire sends the stacktrace for the server, not the client in case of a failure fail(e.getMessage()); } MessageProducer producer = session.createProducer(dest); producer.send(session.createTextMessage("hello")); Wait.assertEquals(1, queue::getMessageCount); connection.start(); Assert.assertNotNull(consumer.receive(500)); } finally { connection.close(); } }
Example 4
Source File: TemporaryDestinationToFromNameTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void testCreateTemporaryQueueThenCreateAQueueFromItsName() throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue tempQueue = session.createTemporaryQueue(); String name = tempQueue.getQueueName(); LOG.info("Created queue named: " + name); Queue createdQueue = session.createQueue(name); assertEquals("created queue not equal to temporary queue", tempQueue, createdQueue); }
Example 5
Source File: MessagingSource.java From iaf with Apache License 2.0 | 5 votes |
private void deleteDynamicQueue(Queue queue) throws IfsaException { if (queue!=null) { try { if (!(queue instanceof TemporaryQueue)) { throw new IfsaException("Queue ["+queue.getQueueName()+"] is not a TemporaryQueue"); } TemporaryQueue tqueue = (TemporaryQueue)queue; tqueue.delete(); } catch (JMSException e) { throw new IfsaException("cannot delete temporary queue",e); } } }
Example 6
Source File: JmsInstrumentationIT.java From apm-agent-java with Apache License 2.0 | 4 votes |
private void verifyQueueSendReceiveOnTracedThread(Queue queue, boolean disableTimestamp) throws Exception { String message = UUID.randomUUID().toString(); Message outgoingMessage = brokerFacade.createTextMessage(message); brokerFacade.send(queue, outgoingMessage, disableTimestamp); Message incomingMessage = resultQ.poll(2, TimeUnit.SECONDS); assertThat(incomingMessage).isNotNull(); verifyMessage(message, incomingMessage); List<Span> spans = reporter.getSpans(); int numSpans = spans.size(); if (!receiveNoWaitFlow.get()) { assertThat(numSpans).isGreaterThanOrEqualTo(3); } final String sendToTestQueueSpanName = "JMS SEND to queue " + queue.getQueueName(); List<Span> sendSpans = spans.stream().filter(span -> span.getNameAsString().equals(sendToTestQueueSpanName)).collect(Collectors.toList()); assertThat(sendSpans).hasSize(1); Span sendSpan = sendSpans.get(0); final String receiveFromTestQueueSpanName = "JMS RECEIVE from queue " + queue.getQueueName(); List<Span> receiveSpans = spans.stream().filter(span -> span.getNameAsString().equals(receiveFromTestQueueSpanName)).collect(Collectors.toList()); assertThat(receiveSpans).hasSize(1); Span receiveSpan = receiveSpans.get(0); final String sendToTestNoopQueueSpanName = "JMS SEND to queue NOOP"; List<Span> sendToNoopSpans = spans.stream().filter(span -> span.getNameAsString().equals(sendToTestNoopQueueSpanName)).collect(Collectors.toList()); Span sendToNoopSpan = null; if (!receiveNoWaitFlow.get()) { assertThat(sendToNoopSpans).hasSize(1); sendToNoopSpan = sendToNoopSpans.get(0); } // rest of spans should be receive spans yielding null messages final String receiveWithNoMessageSpanName = "JMS RECEIVE"; assertThat(spans.stream().filter(span -> span.getNameAsString().equals(receiveWithNoMessageSpanName)).count()).isGreaterThanOrEqualTo(numSpans - 3); //noinspection ConstantConditions Id currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); assertThat(sendSpan.getTraceContext().getTraceId()).isEqualTo(currentTraceId); assertThat(sendSpan.getContext().getMessage().getQueueName()).isEqualTo(queue.getQueueName()); verifySendSpanDestinationDetails(sendSpan, queue.getQueueName()); Id receiveTraceId = receiveSpan.getTraceContext().getTraceId(); List<Transaction> receiveTransactions = reporter.getTransactions().stream().filter(transaction -> transaction.getTraceContext().getTraceId().equals(receiveTraceId)).collect(Collectors.toList()); assertThat(receiveTransactions).hasSize(1); Transaction receiveTransaction = receiveTransactions.get(0); assertThat(receiveSpan.getTraceContext().getParentId()).isEqualTo(receiveTransaction.getTraceContext().getId()); assertThat(receiveSpan.getContext().getMessage().getQueueName()).isEqualTo(queue.getQueueName()); // Body and headers should not be captured for receive spans assertThat(receiveSpan.getContext().getMessage().getBodyForRead()).isNull(); assertThat(receiveSpan.getContext().getMessage().getHeaders()).isEmpty(); // Age should be captured for receive spans, unless disabled if (disableTimestamp) { assertThat(receiveSpan.getContext().getMessage().getAge()).isEqualTo(-1L); } else { assertThat(receiveSpan.getContext().getMessage().getAge()).isGreaterThanOrEqualTo(0); } if (sendToNoopSpan != null) { assertThat(sendToNoopSpan.getTraceContext().getTraceId()).isEqualTo(receiveTraceId); assertThat(sendToNoopSpan.getTraceContext().getParentId()).isEqualTo(receiveTransaction.getTraceContext().getId()); assertThat(sendToNoopSpan.getContext().getMessage().getQueueName()).isEqualTo("NOOP"); verifySendSpanDestinationDetails(sendToNoopSpan, "NOOP"); } }
Example 7
Source File: CreateQueueTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testCreateQueueTempQueue() throws Exception { conn = cf.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue tempQueue = session.createTemporaryQueue(); String tempQueueName = tempQueue.getQueueName(); // assertFalse(tempQueueName.startsWith(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX)); Queue replyQueue = session.createQueue(tempQueueName); MessageProducer producer = session.createProducer(replyQueue); producer.send(session.createMessage()); MessageConsumer consumer = session.createConsumer(replyQueue); conn.start(); assertNotNull(consumer.receive(10000)); }
Example 8
Source File: CreateQueueTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testCreateQueue() throws Exception { conn = cf.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = createQueue("TestQueue"); String queueName = queue.getQueueName(); instanceLog.debug("queue name is " + queueName); // assertFalse(queueName.startsWith(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX)); Queue replyQueue = session.createQueue(queueName); MessageProducer producer = session.createProducer(replyQueue); producer.send(session.createMessage()); MessageConsumer consumer = session.createConsumer(replyQueue); conn.start(); assertNotNull(consumer.receive(10000)); }
Example 9
Source File: IfsaFacade.java From iaf with Apache License 2.0 | 4 votes |
/** * Sends a message,and if transacted, the queueSession is committed. * <p>This method is intended for <b>clients</b>, as <b>server</b>s * will use the <code>sendReply</code>. * @return the correlationID of the sent message */ public TextMessage sendMessage(QueueSession session, QueueSender sender, String message, Map udzMap, String bifName, byte btcData[]) throws IfsaException { try { if (!isRequestor()) { throw new IfsaException(getLogPrefix()+ "Provider cannot use sendMessage, should use sendReply"); } IFSATextMessage msg = (IFSATextMessage)session.createTextMessage(); msg.setText(message); if (udzMap != null && msg instanceof IFSAMessage) { // Handle UDZs log.debug(getLogPrefix()+"add UDZ map to IFSAMessage"); // process the udzMap Map udzObject = (Map)((IFSAMessage) msg).getOutgoingUDZObject(); udzObject.putAll(udzMap); } String replyToQueueName="-"; //Client side if (messageProtocol.equals(IfsaMessageProtocolEnum.REQUEST_REPLY)) { // set reply-to address Queue replyTo=getMessagingSource().getClientReplyQueue(session); msg.setJMSReplyTo(replyTo); replyToQueueName=replyTo.getQueueName(); } if (messageProtocol.equals(IfsaMessageProtocolEnum.FIRE_AND_FORGET)) { // not applicable } if (StringUtils.isNotEmpty(bifName)) { msg.setBifName(bifName); } if (btcData!=null && btcData.length>0) { msg.setBtcData(btcData); } if (log.isDebugEnabled()) { log.debug(getLogPrefix() + " messageProtocol [" + messageProtocol + "] replyToQueueName [" + replyToQueueName + "] sending message [" + message + "]"); } else { if (log.isInfoEnabled()) { log.info(getLogPrefix() + " messageProtocol [" + messageProtocol + "] replyToQueueName [" + replyToQueueName + "] sending message"); } } // send the message sender.send(msg); // perform commit if (isJmsTransacted() && !(messagingSource.isXaEnabledForSure() && JtaUtil.inTransaction())) { session.commit(); log.debug(getLogPrefix()+ "committing (send) transaction"); } return msg; } catch (Exception e) { throw new IfsaException(e); } }