Search in sources :

Example 6 with QueueRequestor

use of javax.jms.QueueRequestor in project wildfly by wildfly.

the class DestinationConfiguration method createQueue.

public void createQueue(ConnectionFactory cf, Queue managementQueue, String queueName) throws JMSException, StartException {
    try (Connection connection = createQueueConnection(cf);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
        connection.start();
        QueueRequestor requestor = new QueueRequestor((QueueSession) session, managementQueue);
        Message m = session.createMessage();
        if (getSelector() != null && !getSelector().isEmpty()) {
            org.apache.activemq.artemis.api.jms.management.JMSManagementHelper.putOperationInvocation(m, ResourceNames.BROKER, "createQueue", queueName, queueName, getSelector(), isDurable(), RoutingType.ANYCAST.name());
        } else {
            org.apache.activemq.artemis.api.jms.management.JMSManagementHelper.putOperationInvocation(m, ResourceNames.BROKER, "createQueue", queueName, queueName, isDurable(), RoutingType.ANYCAST.name());
        }
        Message reply = requestor.request(m);
        ROOT_LOGGER.infof("Creating queue %s returned %s", queueName, reply);
        requestor.close();
        if (!reply.getBooleanProperty("_AMQ_OperationSucceeded")) {
            String body = reply.getBody(String.class);
            if (!destinationAlreadyExist(body)) {
                throw ROOT_LOGGER.remoteDestinationCreationFailed(queueName, body);
            }
        }
        ROOT_LOGGER.infof("Queue %s has been created", queueName);
    }
}
Also used : QueueRequestor(javax.jms.QueueRequestor) Message(javax.jms.Message) Connection(javax.jms.Connection) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session)

Example 7 with QueueRequestor

use of javax.jms.QueueRequestor in project wildfly by wildfly.

the class DestinationConfiguration method destroyTopic.

public void destroyTopic(ConnectionFactory cf, Queue managementQueue, String topicName) throws JMSException {
    try (Connection connection = createQueueConnection(cf);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
        connection.start();
        QueueRequestor requestor = new QueueRequestor((QueueSession) session, managementQueue);
        Message m = session.createMessage();
        org.apache.activemq.artemis.api.jms.management.JMSManagementHelper.putOperationInvocation(m, ResourceNames.BROKER, "deleteAddress", topicName, true);
        Message reply = requestor.request(m);
        requestor.close();
        ROOT_LOGGER.debugf("Deleting topic " + topicName + " returned " + reply);
        if (!reply.getBooleanProperty("_AMQ_OperationSucceeded")) {
            throw ROOT_LOGGER.remoteDestinationDeletionFailed(topicName, reply.getBody(String.class));
        }
        ROOT_LOGGER.debugf("Topic %s has been deleted", topicName);
    }
}
Also used : QueueRequestor(javax.jms.QueueRequestor) Message(javax.jms.Message) Connection(javax.jms.Connection) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session)

Example 8 with QueueRequestor

use of javax.jms.QueueRequestor in project wildfly by wildfly.

the class DestinationConfiguration method createTopic.

public void createTopic(ConnectionFactory cf, Queue managementQueue, String topicName) throws JMSException, StartException {
    try (Connection connection = createQueueConnection(cf);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
        connection.start();
        QueueRequestor requestor = new QueueRequestor((QueueSession) session, managementQueue);
        Message m = session.createMessage();
        org.apache.activemq.artemis.api.jms.management.JMSManagementHelper.putOperationInvocation(m, ResourceNames.BROKER, "createAddress", topicName, RoutingType.MULTICAST.name());
        Message reply = requestor.request(m);
        ROOT_LOGGER.infof("Creating topic %s returned %s", topicName, reply);
        requestor.close();
        if (!reply.getBooleanProperty("_AMQ_OperationSucceeded")) {
            String body = reply.getBody(String.class);
            if (!destinationAlreadyExist(body)) {
                throw ROOT_LOGGER.remoteDestinationCreationFailed(topicName, body);
            }
        }
        ROOT_LOGGER.infof("Topic %s has been created", topicName);
    }
}
Also used : QueueRequestor(javax.jms.QueueRequestor) Message(javax.jms.Message) Connection(javax.jms.Connection) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session)

Example 9 with QueueRequestor

use of javax.jms.QueueRequestor in project wildfly by wildfly.

the class MDB20TopicTestCase method getRemoteNumberOfAllSubscriptions.

private int getRemoteNumberOfAllSubscriptions(String topicName) throws Exception {
    QueueRequestor requestor = new QueueRequestor((QueueSession) session, ActiveMQJMSClient.createQueue("activemq.management"));
    Message m = session.createMessage();
    org.apache.activemq.artemis.api.jms.management.JMSManagementHelper.putAttribute(m, ResourceNames.ADDRESS + "jms.topic." + topicName, "QueueNames");
    Message reply = requestor.request(m);
    if (!reply.getBooleanProperty("_AMQ_OperationSucceeded")) {
        throw new RuntimeException(reply.getBody(String.class));
    }
    Object[] result = (Object[]) JMSManagementHelper.getResult(reply);
    return result.length;
}
Also used : QueueRequestor(javax.jms.QueueRequestor) Message(javax.jms.Message)

Example 10 with QueueRequestor

use of javax.jms.QueueRequestor in project wildfly by wildfly.

the class RemoteActiveMQProviderJMSOperations method createRemoteTopic.

private void createRemoteTopic(String topicName) {
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616", "guest", "guest");
    try (Connection connection = cf.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
        connection.start();
        Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management");
        QueueRequestor requestor = new QueueRequestor((QueueSession) session, managementQueue);
        Message m = session.createMessage();
        org.apache.activemq.artemis.api.jms.management.JMSManagementHelper.putOperationInvocation(m, ResourceNames.BROKER, "createAddress", topicName, RoutingType.MULTICAST.name());
        Message reply = requestor.request(m);
        System.out.println("Creating topic " + topicName + " returned " + reply);
        if (!reply.getBooleanProperty("_AMQ_OperationSucceeded")) {
            String body = reply.getBody(String.class);
            if (!destinationAlreadyExist(body)) {
                System.out.println("Creation of topic " + topicName + " has failed because of " + body);
                throw new JMSOperationsException("Creation of topic " + topicName + " has failed because of " + body);
            }
        }
    } catch (JMSException ex) {
        ex.printStackTrace();
        throw new JMSOperationsException(ex);
    }
    System.out.println("Topic " + topicName + " has been created");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) QueueRequestor(javax.jms.QueueRequestor) Message(javax.jms.Message) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) Queue(javax.jms.Queue) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession)

Aggregations

QueueRequestor (javax.jms.QueueRequestor)19 Message (javax.jms.Message)16 QueueSession (javax.jms.QueueSession)16 Queue (javax.jms.Queue)11 Connection (javax.jms.Connection)9 Session (javax.jms.Session)8 JMSException (javax.jms.JMSException)6 TextMessage (javax.jms.TextMessage)6 QueueConnection (javax.jms.QueueConnection)5 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)4 StringReader (java.io.StringReader)2 List (java.util.List)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageProducer (javax.jms.MessageProducer)2 QueueConnectionFactory (javax.jms.QueueConnectionFactory)2 InitialContext (javax.naming.InitialContext)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 QueueBrowser (javax.jms.QueueBrowser)1