List of usage examples for javax.jms Queue getQueueName
String getQueueName() throws JMSException;
From source file:org.apache.qpid.systest.management.jmx.QueueManagementTest.java
public void testSetNewQueueDescriptionOnExistingQueue() throws Exception { Queue queue = _session.createQueue(getTestQueueName()); createQueueOnBroker(queue);//from w ww.j a v a 2 s. co m final String queueName = queue.getQueueName(); final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName); assertNull("Unexpected description", managedQueue.getDescription()); managedQueue.setDescription(TEST_QUEUE_DESCRIPTION); assertEquals(TEST_QUEUE_DESCRIPTION, managedQueue.getDescription()); }
From source file:org.apache.synapse.transport.jms.JMSUtils.java
/** * Create a JMS Queue using the given connection with the JNDI destination name, and return the * JMS Destination name of the created queue * * @param con the JMS Connection to be used * @param destinationJNDIName the JNDI name of the Queue to be created * @return the JMS Destination name of the created Queue * @throws JMSException on error//from w w w .j a va2s . c om */ public static String createJMSQueue(Connection con, String destinationJNDIName) throws JMSException { try { QueueSession session = ((QueueConnection) con).createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(destinationJNDIName); log.info("JMS Queue with JNDI name : " + destinationJNDIName + " created"); return queue.getQueueName(); } finally { try { con.close(); } catch (JMSException ignore) { } } }
From source file:org.codehaus.stomp.jms.StompSession.java
protected String convertDestination(Destination d) throws JMSException { if (d == null) { return null; }/*from w ww. j a v a2 s. c om*/ StringBuffer buffer = new StringBuffer(); if (d instanceof Topic) { Topic topic = (Topic) d; // if (d instanceof TemporaryTopic) { // buffer.append("/temp-topic/"); // temporaryDestination(topic.getTopicName(), d); // } else { buffer.append("/topic/"); // } buffer.append(topic.getTopicName()); } else { Queue queue = (Queue) d; // if (d instanceof TemporaryQueue) { // buffer.append("/temp-queue/"); // temporaryDestination(queue.getQueueName(), d); // } else { buffer.append("/queue/"); // } buffer.append(queue.getQueueName()); } return buffer.toString(); }
From source file:org.genemania.broker.Worker.java
public synchronized void onMessage(Message msg) { if (msg instanceof TextMessage) { String responseBody = ""; try {// ww w . j a v a 2 s. c om // extract message data Queue queue = (Queue) msg.getJMSDestination(); requestMessage = (TextMessage) msg; LOG.debug("new " + msg.getJMSType() + " message received on queue " + queue.getQueueName() + "[correlation id: " + msg.getJMSCorrelationID() + "]"); responseMessage = session.createTextMessage(); responseMessage.setJMSDestination(requestMessage.getJMSReplyTo()); responseMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT); responseMessage.setJMSCorrelationID(msg.getJMSCorrelationID()); // invoke engine if (queue.getQueueName().equalsIgnoreCase(mqRequestsQueueName)) { if (MessageType.RELATED_GENES.equals(MessageType.fromCode(msg.getJMSType()))) { RelatedGenesRequestMessage data = RelatedGenesRequestMessage .fromXml(requestMessage.getText()); RelatedGenesResponseMessage response = getRelatedGenes(data); responseBody = response.toXml(); } else if (MessageType.TEXT2NETWORK.equals(MessageType.fromCode(msg.getJMSType()))) { UploadNetworkRequestMessage data = UploadNetworkRequestMessage .fromXml(requestMessage.getText()); UploadNetworkResponseMessage response = uploadNetwork(data); responseBody = response.toXml(); } else if (MessageType.PROFILE2NETWORK.equals(MessageType.fromCode(msg.getJMSType()))) { LOG.warn("invoking engine.profile2network: not implemented"); } else { LOG.warn("Unknown jms type: " + msg.getJMSType()); } } processedMessages++; } catch (JMSException e) { LOG.error(e); try { responseBody = buildErrorMessage(e.getMessage(), MessageType.fromCode(msg.getJMSType())); } catch (JMSException x) { LOG.error(x); } } finally { if ((requestMessage != null) && (responseMessage != null)) { try { if (StringUtils.isNotEmpty(responseBody)) { responseMessage.setText(responseBody); LOG.debug("Responding to " + responseMessage.getJMSDestination() + ", msg id " + responseMessage.getJMSCorrelationID() + ", response body size " + (int) responseBody.length()); responseHandler.send(responseMessage.getJMSDestination(), responseMessage); } else { responseBody = buildErrorMessage("Empty response body detected", MessageType.fromCode(msg.getJMSType())); } } catch (JMSException e) { LOG.error("JMS Exception: " + e.getMessage()); try { responseBody = buildErrorMessage(e.getMessage(), MessageType.fromCode(msg.getJMSType())); responseHandler.send(responseMessage); } catch (JMSException e1) { LOG.error("JMS Exception", e1); } } } else { if (requestMessage == null) { LOG.error("request message is null"); } if (responseMessage == null) { LOG.error("response message is null"); } } } } else { LOG.warn("Unknown message type: " + msg); } LOG.info("successfully processed messages: " + processedMessages); }
From source file:org.genemania.broker.Worker.java
private void startNewConnection() throws JMSException { PooledConnectionFactory connectionFactory = new PooledConnectionFactory(brokerUrl); Connection connection = connectionFactory.createConnection(); connection.setExceptionListener(this); connection.start();/*from w w w . j a v a2 s . co m*/ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); responseHandler = session.createProducer(null); Queue requestsQueue = session.createQueue(mqRequestsQueueName); requestHandler = session.createConsumer(requestsQueue); requestHandler.setMessageListener(this); LOG.info("Listening to " + requestsQueue.getQueueName()); }
From source file:org.openanzo.combus.CombusConnection.java
/** * Send a request to a destination and wait for a response * //from www. j a va 2s . c om * @param context * context for this operational call * @param destinationName * destination queue for this request * @param request * request message * @param timeout * timeout for waiting for a response * @return response message * @throws AnzoException * if there was an exception sending request, or a timeout waiting for a response */ public TextMessage requestResponse(IOperationContext context, String destinationName, Message request, long timeout) throws AnzoException { Destination destination = null; if (context.getAttribute(OPTIONS.DATASOURCE) != null) { URI datasourceUri = (URI) context.getAttribute(OPTIONS.DATASOURCE); Queue defaultDestination = (Queue) destinations.get(destinationName); if (datasourceUri.toString().equals("http://openanzo.org/datasource/systemDatasource")) { destination = defaultDestination; } else { String queueNamePrefix = UriGenerator.generateEncapsulatedString("", datasourceUri.toString()) + "/"; try { String[] parts = StringUtils.split(defaultDestination.getQueueName(), '/'); String queue = "services/" + queueNamePrefix + parts[1]; destination = destinations.get(queue); if (destination == null) { destination = session.createQueue(queue); destinations.put(queue, destination); } } catch (JMSException e) { throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName); } } } else { destination = destinations.get(destinationName); if (destination == null) { throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName); } } if (context.getAttribute(COMBUS.TIMEOUT) != null) { timeout = (Long) context.getAttribute(COMBUS.TIMEOUT); } String correlationId = context.getOperationId(); if (correlationId == null) { correlationId = UUID.randomUUID().toString(); } try { request.setJMSCorrelationID(correlationId); request.setJMSReplyTo(tempQueue); request.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION); if (context.getOperationPrincipal() != null && !context.getOperationPrincipal().getName().equals(this.userName)) { request.setStringProperty(SerializationConstants.runAsUser, context.getOperationPrincipal().getName()); } if (context.getAttribute(OPTIONS.PRIORITY) != null) { Integer priority = (Integer) context.getAttribute(OPTIONS.PRIORITY); request.setJMSPriority(priority); messageProducer.setPriority(priority); } else { messageProducer.setPriority(4); } if (context.getAttribute(OPTIONS.SKIPCACHE) != null) { request.setBooleanProperty(OPTIONS.SKIPCACHE, context.getAttribute(OPTIONS.SKIPCACHE, Boolean.class)); } if (log.isTraceEnabled()) { log.trace(LogUtils.COMBUS_MARKER, MessageUtils.prettyPrint(request, "Sending Request: (destination=" + destination + ")")); } messageProducer.send(destination, request); } catch (JMSException jmsex) { performDisconnect(true); throw new AnzoException(ExceptionConstants.COMBUS.COULD_NOT_PUBLISH, jmsex); } lock.lock(); try { Collection<TextMessage> messageSet = correlationIdToMessage.remove(correlationId); long start = System.currentTimeMillis(); while (messageSet == null) { if (timeout <= 0) { try { newMessage.await(2, TimeUnit.SECONDS); } catch (InterruptedException ie) { throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId); } if (closed || closing) { throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId); } messageSet = correlationIdToMessage.remove(correlationId); } else { try { newMessage.await(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException ie) { throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId); } if (closed || closing) { throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId); } messageSet = correlationIdToMessage.remove(correlationId); if (!connected) { log.error(LogUtils.COMBUS_MARKER, "Request Response failed because connection was closed"); throw new AnzoException(ExceptionConstants.COMBUS.JMS_NOT_CONNECTED, correlationId); } if (messageSet == null && ((timeout > 0) && ((System.currentTimeMillis() - start) > timeout))) { throw new AnzoException(ExceptionConstants.COMBUS.NO_SERVER_RESPONSE, correlationId); } } } try { TextMessage message = messageSet.iterator().next(); if (log.isTraceEnabled()) { log.trace(LogUtils.COMBUS_MARKER, MessageUtils.prettyPrint(message, "Received Response:")); } if (message.getBooleanProperty(SerializationConstants.operationFailed)) { long errorCodes = message.propertyExists(SerializationConstants.errorTags) ? message.getLongProperty(SerializationConstants.errorCode) : ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION; // if available, use enumerated args, since these can be reconstruct an AnzoException correctly. List<String> args = new ArrayList<String>(); for (int i = 0; true; i++) { String errorArg = message.getStringProperty(SerializationConstants.errorMessageArg + i); if (errorArg == null) { break; } args.add(errorArg); } // NOTE: This doesn't really make any sense, but it was here before and it's better to be too verbose than not verbose enough // when it comes to error messages, so it stays. For now at least. -jpbetz if (args.isEmpty()) { args.add(message.getText()); } throw new AnzoException(errorCodes, args.toArray(new String[0])); } /*Object prp = context.getAttribute("populateResponseProperties"); if (prp != null && ((Boolean) prp)) { HashMap<String, Object> props = new HashMap<String, Object>(); Enumeration<String> keys = message.getPropertyNames(); while (keys.hasMoreElements()) { String key = keys.nextElement(); props.put(key, message.getObjectProperty(key)); } context.setAttribute("responseProperties", props); }*/ return message; } catch (JMSException jmsex) { log.debug(LogUtils.COMBUS_MARKER, Messages.formatString( ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "request response"), jmsex); } return null; } finally { lock.unlock(); } }
From source file:org.openanzo.combus.CombusConnection.java
/** * Send a request to a destination and wait for a response * //from ww w.j ava 2s . c om * @param context * context for this operational call * @param destinationName * destination queue for this request * @param request * request message * @param timeout * timeout for waiting for a response * @param messageHandler * the handler of multiple messages * @throws AnzoException * if there was an exception sending request, or a timeout waiting for a response */ public void requestMultipleResponse(IOperationContext context, String destinationName, Message request, long timeout, IMessageHandler messageHandler) throws AnzoException { Destination destination = null; if (context.getAttribute(OPTIONS.DATASOURCE) != null) { URI datasourceUri = (URI) context.getAttribute(OPTIONS.DATASOURCE); Queue defaultDestination = (Queue) destinations.get(destinationName); if (datasourceUri.toString().equals("http://openanzo.org/datasource/systemDatasource")) { destination = defaultDestination; } else { String queueNamePrefix = UriGenerator.generateEncapsulatedString("", datasourceUri.toString()) + "/"; try { String[] parts = StringUtils.split(defaultDestination.getQueueName(), '/'); String queue = "services/" + queueNamePrefix + parts[1]; destination = destinations.get(queue); if (destination == null) { destination = session.createQueue(queue); destinations.put(queue, destination); } } catch (JMSException e) { throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName); } } } else { destination = destinations.get(destinationName); if (destination == null) { throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName); } } String correlationId = context.getOperationId(); if (correlationId == null) { correlationId = UUID.randomUUID().toString(); } try { request.setJMSCorrelationID(correlationId); request.setJMSReplyTo(tempQueue); request.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION); if (context.getOperationPrincipal() != null && !context.getOperationPrincipal().getName().equals(this.userName)) { request.setStringProperty(SerializationConstants.runAsUser, context.getOperationPrincipal().getName()); } if (context.getAttribute(OPTIONS.PRIORITY) != null) { Integer priority = (Integer) context.getAttribute(OPTIONS.PRIORITY); request.setJMSPriority(priority); messageProducer.setPriority(priority); } else { messageProducer.setPriority(4); } if (context.getAttribute(OPTIONS.SKIPCACHE) != null) { request.setBooleanProperty(OPTIONS.SKIPCACHE, context.getAttribute(OPTIONS.SKIPCACHE, Boolean.class)); } if (context.getAttribute(OPTIONS.INCLUDEMETADATAGRAPHS) != null) { request.setBooleanProperty(OPTIONS.INCLUDEMETADATAGRAPHS, context.getAttribute(OPTIONS.INCLUDEMETADATAGRAPHS, Boolean.class)); } if (log.isTraceEnabled()) { log.trace(LogUtils.COMBUS_MARKER, MessageUtils.prettyPrint(request, "Sending Request: (destination=" + destination + ")")); } messageProducer.send(destination, request); } catch (JMSException jmsex) { performDisconnect(true); throw new AnzoException(ExceptionConstants.COMBUS.COULD_NOT_PUBLISH, jmsex); } lock.lock(); try { long start = System.currentTimeMillis(); boolean done = false; int seq = 0; while (!done) { Collection<TextMessage> messageSet = correlationIdToMessage.remove(correlationId); while (messageSet == null) { if (timeout <= 0) { try { newMessage.await(2, TimeUnit.SECONDS); } catch (InterruptedException ie) { throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId); } if (closed || closing) { throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId); } messageSet = correlationIdToMessage.remove(correlationId); } else { try { newMessage.await(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException ie) { throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId); } if (closed || closing) { throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId); } messageSet = correlationIdToMessage.remove(correlationId); if (!connected) { log.error(LogUtils.COMBUS_MARKER, Messages.formatString( ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "connection closed")); throw new AnzoException(ExceptionConstants.COMBUS.JMS_NOT_CONNECTED, correlationId); } if (messageSet == null && ((timeout > -1) && ((System.currentTimeMillis() - start) > timeout))) { throw new AnzoException(ExceptionConstants.COMBUS.NO_SERVER_RESPONSE, correlationId); } } } try { for (TextMessage message : messageSet) { if (log.isTraceEnabled()) { log.trace(LogUtils.COMBUS_MARKER, MessageUtils.prettyPrint(message, "Recieved Response:")); } if (message.propertyExists("done")) { done = message.getBooleanProperty("done"); } else { done = true; } if (message.propertyExists("sequence")) { int sequence = message.getIntProperty("sequence"); if (sequence != seq) { throw new AnzoException(ExceptionConstants.COMBUS.NO_SERVER_RESPONSE, correlationId); } else { seq++; } } int totalSize = 0; if (message.propertyExists(SerializationConstants.totalSolutions)) { totalSize = message.getIntProperty(SerializationConstants.totalSolutions); } if (message.getBooleanProperty(SerializationConstants.operationFailed)) { long errorCodes = message.propertyExists(SerializationConstants.errorTags) ? message.getLongProperty(SerializationConstants.errorCode) : ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION; // if available, use enumerated args, since these can be reconstruct an AnzoException correctly. List<String> args = new ArrayList<String>(); for (int i = 0; true; i++) { String errorArg = message .getStringProperty(SerializationConstants.errorMessageArg + i); if (errorArg == null) { break; } args.add(errorArg); } // NOTE: This doesn't really make any sense, but it was here before and it's better to be too verbose than not verbose enough // when it comes to error messages, so it stays. For now at least. -jpbetz if (args.isEmpty()) { args.add(message.getText()); } throw new AnzoException(errorCodes, args.toArray(new String[0])); } else { messageHandler.handleMessage(message, seq, done, totalSize); } } } catch (JMSException jmsex) { log.debug(LogUtils.COMBUS_MARKER, Messages.formatString( ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "request multiple response"), jmsex); } } } finally { lock.unlock(); } }
From source file:org.wso2.carbon.andes.ui.client.QueueReceiverClient.java
/** * Method to purge a queue as user request through the client. * @param queue javax.jms.Queue object of Queue that needs to be purged. * @return deleted number of messages from the queue. * @throws JMSException//from www. j a v a 2s . co m */ public int purgeQueue(Queue queue) throws JMSException { int messageCount = 0; while (queueConsumer.receive(10000) != null) { messageCount++; } log.info("Executed purge queue operation for the queue: " + queue.getQueueName() + " and removed " + messageCount + " messages"); return messageCount; }