List of usage examples for javax.jms Queue getQueueName
String getQueueName() throws JMSException;
From source file:fr.xebia.springframework.jms.ManagedDefaultMessageListenerContainer.java
public ObjectName getObjectName() throws MalformedObjectNameException { if (objectName == null) { String destinationName = getDestinationName(); Destination destination = getDestination(); if (destinationName == null && destination != null) { try { if (destination instanceof Queue) { Queue queue = (Queue) destination; destinationName = queue.getQueueName(); } else if (destination instanceof Topic) { Topic topic = (Topic) destination; destinationName = topic.getTopicName(); }/* ww w .j ava 2 s. co m*/ } catch (JMSException e) { throw new UncategorizedJmsException(e); } } objectName = ObjectName.getInstance("javax.jms:type=MessageListenerContainer,name=" + ObjectName.quote(getBeanName()) + ",destination=" + destinationName); } return objectName; }
From source file:com.solveapuzzle.mapping.agnostic.JmsMessageProducer.java
/** * Generates JMS messages//from w ww . ja va 2s . c o m * * @throws IOException */ @PostConstruct public void generateMessages() throws JMSException, IOException { for (int i = 0; i < messageCount; i++) { final int index = i; final String text = "Message number is " + i + "."; InputStream inXML = this.getClass().getClassLoader().getResourceAsStream("inXML.xml"); final String xml = IOUtils.toString(inXML); String correlationId = UUID.randomUUID().toString(); if (replyToQueue == null) { throw new RuntimeException("No Reply to Queue!"); } MessageCreator creator = new XmlRequestReplyMessageCreator(correlationId, xml, index, replyToQueue); javax.jms.Queue queue = (javax.jms.Queue) replyToQueue; logger.info("ReplyTo Queue name (Producer)= " + queue.getQueueName()); template.send(creator); } }
From source file:com.solveapuzzle.mapping.agnostic.JmsMessageListener.java
/** * Implementation of <code>MessageListener</code>. *//*from w w w . j a v a 2 s.c o m*/ public void onMessage(Message message) { try { int messageCount = message.getIntProperty(JmsMessageProducer.MESSAGE_COUNT); logger.info("Processed message '{}'. value={}", message, messageCount); counter.incrementAndGet(); if (message instanceof TextMessage) { TextMessage tm = (TextMessage) message; String msg = tm.getText(); logger.info(" Read Transform property " + message.getStringProperty(TRANSFORM)); try { String parser = tm.getStringProperty(PARSER); String key = tm.getStringProperty(TRANSFORM); logger.info(" Read Transform propertys " + parser + " " + key); String response = engine.onTransformEvent(this.createConfig(parser, key), tm.getText(), Charset.defaultCharset()); logger.info(" Response " + response); logger.info("message ReplyTo ID " + tm.getJMSCorrelationID()); tm.setJMSDestination(this.outDestination); javax.jms.Queue queue = (javax.jms.Queue) tm.getJMSDestination(); logger.info("ReplyTo Queue name = " + queue.getQueueName()); tm.clearBody(); tm.setText(response); // Push to response queue } catch (MappingException e) { logger.error("Mapping exception from transformation ", e); // push to mapping error Queue? // May be fixable with input xml change or due to data quality, invalid against schema throw new RuntimeException(e); } catch (ConfigurationException e) { logger.error("Configuration exception from transformation", e); // Can't fix - dead letter queue - but worth tracing what config went missing? throw new RuntimeException(e); } } } catch (JMSException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.apache.james.queue.activemq.ActiveMQMailQueue.java
/** * Try to use ActiveMQ StatisticsPlugin to get size and if that fails * fallback to {@link JMSMailQueue#getSize()} */// w w w . ja v a 2 s . co m @Override public long getSize() throws MailQueueException { Connection connection = null; Session session = null; MessageConsumer consumer = null; MessageProducer producer = null; TemporaryQueue replyTo = null; long size = -1; try { connection = connectionFactory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); replyTo = session.createTemporaryQueue(); consumer = session.createConsumer(replyTo); Queue myQueue = session.createQueue(queuename); producer = session.createProducer(null); String queueName = "ActiveMQ.Statistics.Destination." + myQueue.getQueueName(); Queue query = session.createQueue(queueName); Message msg = session.createMessage(); msg.setJMSReplyTo(replyTo); producer.send(query, msg); MapMessage reply = (MapMessage) consumer.receive(2000); if (reply != null && reply.itemExists("size")) { try { size = reply.getLong("size"); return size; } catch (NumberFormatException e) { // if we hit this we can't calculate the size so just catch // it } } } catch (Exception e) { throw new MailQueueException("Unable to remove mails", e); } finally { if (consumer != null) { try { consumer.close(); } catch (JMSException e1) { e1.printStackTrace(); // ignore on rollback } } if (producer != null) { try { producer.close(); } catch (JMSException e1) { // ignore on rollback } } if (replyTo != null) { try { // we need to delete the temporary queue to be sure we will // free up memory if thats not done and a pool is used // its possible that we will register a new mbean in jmx for // every TemporaryQueue which will never get unregistered replyTo.delete(); } catch (JMSException e) { } } try { if (session != null) session.close(); } catch (JMSException e1) { // ignore here } try { if (connection != null) connection.close(); } catch (JMSException e1) { // ignore here } } // if we came to this point we should just fallback to super method return super.getSize(); }
From source file:net.timewalker.ffmq4.local.session.LocalMessageConsumer.java
protected final void initDestination() throws JMSException { // Security : a consumer destination may only be set at creation time // so we check permissions here once and for all. LocalConnection conn = (LocalConnection) session.getConnection(); if (conn.isSecurityEnabled()) { if (destination instanceof Queue) { String queueName = ((Queue) destination).getQueueName(); if (conn.isRegisteredTemporaryQueue(queueName)) { // OK, temporary destination } else if (queueName.equals(FFMQConstants.ADM_REQUEST_QUEUE)) { // Only the internal admin thread can consume on this queue if (conn.getSecurityContext() != null) throw new FFMQException("Access denied to administration queue " + queueName, "ACCESS_DENIED"); } else if (queueName.equals(FFMQConstants.ADM_REPLY_QUEUE)) { conn.checkPermission(Resource.SERVER, Action.REMOTE_ADMIN); } else { // Standard queue conn.checkPermission(destination, Action.CONSUME); }/*from ww w. ja va 2 s .co m*/ } else if (destination instanceof Topic) { String topicName = ((Topic) destination).getTopicName(); if (conn.isRegisteredTemporaryTopic(topicName)) { // OK, temporary destination } else { // Standard topic conn.checkPermission(destination, Action.CONSUME); } } } // Lookup a local destination object from the given reference if (destination instanceof Queue) { Queue queueRef = (Queue) destination; this.localQueue = engine.getLocalQueue(queueRef.getQueueName()); // Check temporary destinations scope (JMS Spec 4.4.3 p2) session.checkTemporaryDestinationScope(localQueue); this.localQueue.registerConsumer(this); } else if (destination instanceof Topic) { Topic topicRef = (Topic) destination; this.localTopic = engine.getLocalTopic(topicRef.getTopicName()); // Check temporary destinations scope (JMS Spec 4.4.3 p2) session.checkTemporaryDestinationScope(localTopic); // Deploy a local queue for this consumer TopicDefinition topicDef = this.localTopic.getDefinition(); QueueDefinition tempDef = topicDef.createQueueDefinition(topicRef.getTopicName(), subscriberId, !isDurable()); if (engine.localQueueExists(tempDef.getName())) this.localQueue = engine.getLocalQueue(tempDef.getName()); else this.localQueue = engine.createQueue(tempDef); // Register on both the queue and topic this.localQueue.registerConsumer(this); this.localTopic.registerConsumer(this); } else throw new InvalidDestinationException("Unsupported destination : " + destination); }
From source file:net.timewalker.ffmq4.local.session.LocalSession.java
private AbstractLocalDestination getLocalDestination(AbstractMessage message) throws JMSException { Destination destination = message.getJMSDestination(); if (destination instanceof Queue) { Queue queueRef = (Queue) destination; return engine.getLocalQueue(queueRef.getQueueName()); } else if (destination instanceof Topic) { Topic topicRef = (Topic) destination; return engine.getLocalTopic(topicRef.getTopicName()); } else//w w w . j a v a 2s . c om throw new InvalidDestinationException("Unsupported destination : " + destination); }
From source file:net.timewalker.ffmq4.local.session.LocalSession.java
public QueueBrowser createBrowser(IntegerID browserId, Queue queueRef, String messageSelector) throws JMSException { externalAccessLock.readLock().lock(); try {/*from w ww . j a va 2s . c om*/ checkNotClosed(); LocalQueue localQueue = engine.getLocalQueue(queueRef.getQueueName()); // Check temporary destinations scope (JMS Spec 4.4.3 p2) checkTemporaryDestinationScope(localQueue); LocalQueueBrowser browser = new LocalQueueBrowser(this, localQueue, messageSelector, browserId); registerBrowser(browser); return browser; } finally { externalAccessLock.readLock().unlock(); } }
From source file:nl.nn.adapterframework.extensions.ifsa.jms.IfsaFacade.java
/** * 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 *//* w w w .j a v a 2 s . c om*/ 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); } }
From source file:nl.nn.adapterframework.jms.MessagingSource.java
private void deleteDynamicQueue(Queue queue) throws IfsaException { if (queue != null) { try {/* w w w . j ava 2s .c o m*/ 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); } } }
From source file:org.apache.activemq.bugs.AMQ6133PersistJMSRedeliveryTest.java
private void consumerAndRollback(int iteration) throws Exception { Connection connection = createConnection(); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); Queue queue = session.createQueue(QUEUE_NAME); MessageConsumer consumer = session.createConsumer(queue); long msgCount = getProxyToQueue(queue.getQueueName()).getQueueSize(); for (int i = 0; i < msgCount; ++i) { Message message = consumer.receive(50000); assertNotNull(message);//from w w w .ja va2s.c o m if (iteration > 0) { assertTrue(message.getJMSRedelivered()); } } connection.close(); }