Search in sources :

Example 1 with AMQConnectionFactory

use of org.apache.qpid.client.AMQConnectionFactory in project jmeter-plugins by undera.

the class JmsUtil method runTest.

@Override
public SampleResult runTest(JavaSamplerContext ctx) {
    SampleResult result = new SampleResult();
    result.setContentType("plain/text");
    result.setDataType(SampleResult.TEXT);
    result.setDataEncoding(SampleResult.DEFAULT_HTTP_ENCODING);
    String connectionUrl = ctx.getParameter("connection.url");
    String bindingUrl = ctx.getParameter("binding.url");
    String message = ctx.getParameter("message");
    if (connectionUrl == null || "".equals(connectionUrl)) {
        result.setSuccessful(false);
        result.setResponseMessage("Connection URL cannot be empty.");
        result.setResponseCode("0xDEAD");
    } else {
        if (bindingUrl == null || "".equals(bindingUrl)) {
            result.setSuccessful(false);
            result.setResponseMessage("Binding URL cannot be empty.");
            result.setResponseCode("0xDEAD");
        } else {
            try {
                ConnectionFactory connectionFactory = new AMQConnectionFactory(connectionUrl);
                AMQBindingURL burl = new AMQBindingURL(bindingUrl);
                Destination destinationProducer = new AMQAnyDestination(burl);
                JmsTemplate sender = new JmsTemplate();
                sender.setConnectionFactory(connectionFactory);
                sender.setDefaultDestination(destinationProducer);
                BinaryMessageConverter bmc = new BinaryMessageConverter();
                sender.setMessageConverter(bmc);
                BinaryMessagepostProcessor postProcessor = new BinaryMessagepostProcessor();
                sender.setDeliveryMode(2);
                int rt = 30000;
                try {
                    rt = Integer.valueOf(ctx.getParameter("receive.timeout"));
                } catch (Exception e) {
                }
                sender.setReceiveTimeout(rt);
                String direction = ctx.getParameter("direction");
                if (direction == null || "".equals(direction)) {
                    direction = "send";
                }
                if (direction.toLowerCase().equals("send")) {
                    Map<String, String> mp = getMessageProperties(ctx.getParameter("header.properties"));
                    postProcessor.setMessageProperties(mp);
                    sender.convertAndSend((Object) message, postProcessor);
                    result.setSuccessful(true);
                    result.setResponseMessage("Message sent.");
                } else {
                    if (direction.toLowerCase().equals("receive")) {
                        System.out.println("Receive");
                        String messageSelector = ctx.getParameter("message.selector");
                        System.out.println("Selector: " + messageSelector);
                        Object obj = null;
                        if (messageSelector != null && !"".equals(messageSelector)) {
                            obj = sender.receiveSelectedAndConvert(messageSelector);
                        } else {
                            obj = sender.receiveAndConvert();
                        }
                        if (obj != null) {
                            result.setSuccessful(true);
                            result.setResponseData(obj.toString().getBytes());
                            String paramName = ctx.getParameter("header.property.reference");
                            if (paramName != null && !"".equals(paramName))
                                JMeterUtils.setProperty(paramName, concatProperties(bmc.getMessageProperties()));
                        } else {
                            result.setSuccessful(false);
                            result.setResponseData("Conection timeout".getBytes());
                        }
                    } else {
                        result.setSuccessful(false);
                        result.setResponseMessage("Unknown direction.");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                result.setSuccessful(false);
                result.setResponseMessage("Exception");
                result.setResponseData(e.getMessage().getBytes());
            }
        }
    }
    return result;
}
Also used : AMQAnyDestination(org.apache.qpid.client.AMQAnyDestination) Destination(javax.jms.Destination) AMQBindingURL(org.apache.qpid.url.AMQBindingURL) AMQConnectionFactory(org.apache.qpid.client.AMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) AMQAnyDestination(org.apache.qpid.client.AMQAnyDestination) AMQConnectionFactory(org.apache.qpid.client.AMQConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 2 with AMQConnectionFactory

use of org.apache.qpid.client.AMQConnectionFactory in project quickstarts by jboss-switchyard.

the class QpidClient method main.

public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    Properties properties = new Properties();
    properties.load(QpidClient.class.getResourceAsStream("/amqp.properties"));
    AMQConnectionFactory connectionFactory = new AMQConnectionFactory(properties.getProperty("qpidConnectionfactory"));
    Connection connection = connectionFactory.createConnection("guest", "guest");
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    System.out.println("Type your name:");
    String name = reader.readLine();
    TextMessage textMessage = session.createTextMessage(name);
    MessageProducer producer = session.createProducer(session.createQueue("ping"));
    producer.send(textMessage);
    System.out.println("Send message " + name);
    session.close();
    connection.stop();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Connection(javax.jms.Connection) AMQConnectionFactory(org.apache.qpid.client.AMQConnectionFactory) MessageProducer(javax.jms.MessageProducer) Properties(java.util.Properties) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 3 with AMQConnectionFactory

use of org.apache.qpid.client.AMQConnectionFactory in project candlepin by candlepin.

the class QpidConnection method createConnectionFactory.

private AMQConnectionFactory createConnectionFactory() throws NamingException {
    log.debug("looking up QpidConnectionfactory");
    AMQConnectionFactory connectionFactory = (AMQConnectionFactory) ctx.lookup("qpidConnectionfactory");
    Map<String, String> configProperties = config.buildBrokerDetails(ctx);
    for (BrokerDetails broker : connectionFactory.getConnectionURL().getAllBrokerDetails()) {
        for (Entry<String, String> prop : configProperties.entrySet()) {
            // specified in the broker urls.
            if (prop.getKey().equals("retries") || prop.getKey().equals("connectdelay")) {
                if (broker.getProperty(prop.getKey()) != null) {
                    continue;
                }
            }
            broker.setProperty(prop.getKey(), prop.getValue());
        }
        log.debug("Broker configured: " + broker);
    }
    log.info("AMQP connection factory created.");
    return connectionFactory;
}
Also used : AMQConnectionFactory(org.apache.qpid.client.AMQConnectionFactory) BrokerDetails(org.apache.qpid.jms.BrokerDetails)

Aggregations

AMQConnectionFactory (org.apache.qpid.client.AMQConnectionFactory)3 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Properties (java.util.Properties)1 Connection (javax.jms.Connection)1 ConnectionFactory (javax.jms.ConnectionFactory)1 Destination (javax.jms.Destination)1 MessageProducer (javax.jms.MessageProducer)1 Session (javax.jms.Session)1 TextMessage (javax.jms.TextMessage)1 SampleResult (org.apache.jmeter.samplers.SampleResult)1 AMQAnyDestination (org.apache.qpid.client.AMQAnyDestination)1 BrokerDetails (org.apache.qpid.jms.BrokerDetails)1 AMQBindingURL (org.apache.qpid.url.AMQBindingURL)1 JmsTemplate (org.springframework.jms.core.JmsTemplate)1