javax.jms.QueueRequestor Java Examples

The following examples show how to use javax.jms.QueueRequestor. 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: QueueBridgeTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
   super.setUp();
   context = createApplicationContext();

   createConnections();

   requestServerSession = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue theQueue = requestServerSession.createQueue(getClass().getName());
   requestServerConsumer = requestServerSession.createConsumer(theQueue);
   requestServerConsumer.setMessageListener(this);
   requestServerProducer = requestServerSession.createProducer(null);

   QueueSession session = remoteConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   requestor = new QueueRequestor(session, theQueue);
}
 
Example #2
Source File: PurgeCommandTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
   super.setUp();

   context = createApplicationContext();

   createConnections();

   requestServerSession = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   theQueue = requestServerSession.createQueue(QUEUE_NAME);
   requestServerConsumer = requestServerSession.createConsumer(theQueue);
   requestServerProducer = requestServerSession.createProducer(null);

   QueueSession session = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   requestor = new QueueRequestor(session, theQueue);
}
 
Example #3
Source File: AbstractArquillianTest.java    From training with MIT License 5 votes vote down vote up
@Deployment
public static JavaArchive getDeployment() {
	return ShrinkWrap.create(JavaArchive.class, "test.jar")
			.addPackages(true, "victor.training.jee6")
			.addPackages(true, "org.mockito")
			.addPackages(true, "org.apache.tools")
			.addPackages(true, "org.objenesis")
			.addClass(QueueRequestor.class)
			.addAsManifestResource(new File("src/main/webapp/WEB-INF/beans.xml"))
			;
}
 
Example #4
Source File: JMSWrapper.java    From core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Dynamically creates a topic. This goes against the normal idea
    * that JMS queues and topics should managed administratively, using
    * management tools. But for some applications this would be too 
    * burdensome. The user would have to additionally know about the
    * administration tools as well. Given that might be creating quite
    * a few AVL feeds, each one being a separate topic, this could be
    * a real nuisance.
    * 
 * @param topicName
 * @return true if topic created successfully
 * @throws JMSException
 */
private boolean createTopic(String topicName) throws JMSException {
	QueueConnectionFactory queueConnectionFactory = 
			(QueueConnectionFactory) connectionFactory;
	QueueConnection connection = queueConnectionFactory.createQueueConnection();

	Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management");
	QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
	connection.start();
	Message message = session.createMessage();
	JMSManagementHelper.putOperationInvocation(message, 
			"jms.server", 
			"createTopic", // management command
			topicName,     // Name in hornetq
			topicName);    // JNDI name. This peculiar seemingly undocumented 
						   // parameter is needed so that can use JNDI to access 
	                       // the dynamically created topic. Found info on doing 
	                       // this at https://community.jboss.org/thread/165355 .
	QueueRequestor requestor = new QueueRequestor(session, managementQueue);

	// Determine if was successful
	Message reply = requestor.request(message);
	boolean topicCreated = JMSManagementHelper.hasOperationSucceeded(reply);
	
	if (topicCreated)
		logger.info("Dynamically created topic \"" + topicName + "\"");
	else
		logger.error("Failed to dynamically created topic \"" + topicName + "\"");
	
	// Return whether successful
	return topicCreated;
}
 
Example #5
Source File: EJBTest.java    From training with MIT License 4 votes vote down vote up
@Deployment
public static JavaArchive getDeployment() {
	return ShrinkWrap.create(JavaArchive.class, "test.jar").addPackages(true, "victor.training.ejb")
			.addPackages(true, "org.mockito")
			.addPackages(true, "org.objenesis").addClass(QueueRequestor.class);
}
 
Example #6
Source File: PreacknowledgeExample.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private static int getMessageCount(final Connection connection) throws Exception {
   QueueSession session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

   Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management");

   QueueRequestor requestor = new QueueRequestor(session, managementQueue);

   connection.start();

   Message m = session.createMessage();

   JMSManagementHelper.putAttribute(m, ResourceNames.QUEUE + "exampleQueue", "messageCount");

   Message response = requestor.request(m);

   int messageCount = (Integer) JMSManagementHelper.getResult(response, Integer.class);

   return messageCount;
}
 
Example #7
Source File: ArtemisFeatureTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 5 * 60 * 1000)
public void test() throws Throwable {
   executeCommand("bundle:list");

   withinReason(new Callable<Boolean>() {
      @Override
      public Boolean call() throws Exception {
         assertTrue("artemis bundle installed", verifyBundleInstalled("artemis-server-osgi"));
         return true;
      }
   });

   Object service = waitForService("(objectClass=org.apache.activemq.artemis.core.server.ActiveMQServer)", 30000);
   assertNotNull(service);
   log.debug("have service " + service);

   executeCommand("service:list -n");

   Connection connection = null;
   try {
      JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:5672");
      connection = factory.createConnection(USER, PASSWORD);
      connection.start();

      QueueSession sess = (QueueSession) connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
      Queue queue = sess.createQueue("exampleQueue");
      MessageProducer producer = sess.createProducer(queue);
      producer.send(sess.createTextMessage("TEST"));

      // Test browsing
      try (QueueBrowser browser = sess.createBrowser(queue)) {
         Enumeration messages = browser.getEnumeration();
         while (messages.hasMoreElements()) {
            messages.nextElement();
         }
      }

      // Test management
      Queue managementQueue = sess.createQueue("activemq.management");
      QueueRequestor requestor = new QueueRequestor(sess, managementQueue);
      connection.start();
      TextMessage m = sess.createTextMessage();
      m.setStringProperty("_AMQ_ResourceName", "broker");
      m.setStringProperty("_AMQ_OperationName", "getQueueNames");
      m.setText("[\"ANYCAST\"]");
      Message reply = requestor.request(m);
      String json = ((TextMessage) reply).getText();
      JsonArray array = Json.createReader(new StringReader(json)).readArray();
      List<JsonString> queues = (List<JsonString>) array.get(0);
      assertNotNull(queues);
      assertFalse(queues.isEmpty());

      MessageConsumer consumer = sess.createConsumer(queue);
      Message msg = consumer.receive(5000);
      assertNotNull(msg);
   } finally {
      if (connection != null) {
         connection.close();
      }
   }
}