You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Thomas Hehl <th...@heavyweightsoftware.com> on 2016/06/28 08:43:37 UTC

Blueprint request/reply pattern

Please see my question regarding Active MQ request/reply here: 
http://stackoverflow.com/questions/38060148/trying-to-capture-response-from-activemq-in-my-camel-route

Thanks!



Re: Blueprint request/reply pattern

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
Here’s the test that works with Camel 2.15.1 (it works with 2.17.1 as well).  I had some method signatures that must have been updated/added to the test support classes in the later versions of Camel.  I didn’t have to change the blueprint XML.

package com.pronoia.camel;

import java.util.Dictionary;
import java.util.Map;

import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.activemq.junit.EmbeddedActiveMQBroker;
import org.apache.camel.EndpointInject;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsConstants;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.apache.camel.util.KeyValueHolder;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

public class BlueprintRequestResponseTest extends CamelBlueprintTestSupport {
    @Rule
    public EmbeddedActiveMQBroker broker = new EmbeddedActiveMQBroker();

    @EndpointInject( uri = "mock://target")
    MockEndpoint target;

    @Override
    protected String getBlueprintDescriptor() {
        return "/OSGI-INF/blueprint/blueprint-request-response.xml";
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from( "test-broker://queue:testQueue")
                        .setBody().constant( "Response Message")
                        .to( "test-broker://queue://bar?exchangePattern=InOnly")
                        ;

            }
        };
    }

    @Test
    public void testRoute() throws Exception {
        target.expectedBodiesReceived("Response Message");

        template.sendBody("direct://trigger", "Trigger Message");

        assertMockEndpointsSatisfied();
    }

}

> On Jun 28, 2016, at 10:38 AM, Quinn Stevenson <qu...@pronoia-solutions.com> wrote:
> 
> I pulled up an old sample and changed it, so it’s running against 2.17-SNAPSNOT.  I’m trying to get it to work again 2.15.1 (community - not Fuse), but it looks like some of my test classes don’t compile against that version.  I’ll get them to compile and then see if the test still work.
> 
> I’m using IntelliJ for my IDE
> 
>> On Jun 28, 2016, at 10:36 AM, Thomas Hehl <th...@heavyweightsoftware.com> wrote:
>> 
>> What version are you running, Quinn?
>> 
>> 
>> On 6/28/2016 12:26 PM, Thomas Hehl wrote:
>>> JBoss Developer Studio
>>> 
>>> Version: 8.1.0.GA
>>> Build id: GA-v20150327-1349-B467
>>> Build date: 20150327-1349
>>> 
>>> Apache Camel 2.15.1.redhat-621084
>>> 
>>> It's the developer studio that's crapping out.
>>> 
>>> 
>>> On 6/28/2016 12:23 PM, Quinn Stevenson wrote:
>>>> Hmmm…  I just ran the unit test using this XML again, and I’m not seeing any errors.  What version of Camel are you using?
>>>> 
>>>>> On Jun 28, 2016, at 10:21 AM, Thomas Hehl <th...@heavyweightsoftware.com> wrote:
>>>>> 
>>>>> I cannot get your XML to parse. It's throwing exceptions.
>>>>> 
>>>>> 
>>>>> On 6/28/2016 11:57 AM, Quinn Stevenson wrote:
>>>>>> <bean id="test-broker" class="org.apache.activemq.camel.component.ActiveMQComponent">
>>>>>>        <property name="brokerURL" value="vm://embedded-broker?create=false"/>
>>>>>>    </bean>
>>>>>> 
>>>>>>    <camel:camelContext id="blueprint-request-response-context" xmlns="http://camel.apache.org/schema/blueprint">
>>>>>>        <route id="jms-request-response">
>>>>>>            <from uri="direct://trigger" />
>>>>>>            <to uri="test-broker://queue:testQueue?useMessageIDAsCorrelationID=true" pattern="InOut"/>
>>>>>>            <log message="Response: ${body}" />
>>>>>>            <to uri="mock://target"/>
>>>>>>        </route>
>>>>>>    </camel:camelContext>
>>>>>> </blueprint>
>>> 
>> 
> 


Re: Blueprint request/reply pattern

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
I pulled up an old sample and changed it, so it’s running against 2.17-SNAPSNOT.  I’m trying to get it to work again 2.15.1 (community - not Fuse), but it looks like some of my test classes don’t compile against that version.  I’ll get them to compile and then see if the test still work.

I’m using IntelliJ for my IDE

> On Jun 28, 2016, at 10:36 AM, Thomas Hehl <th...@heavyweightsoftware.com> wrote:
> 
> What version are you running, Quinn?
> 
> 
> On 6/28/2016 12:26 PM, Thomas Hehl wrote:
>> JBoss Developer Studio
>> 
>> Version: 8.1.0.GA
>> Build id: GA-v20150327-1349-B467
>> Build date: 20150327-1349
>> 
>> Apache Camel 2.15.1.redhat-621084
>> 
>> It's the developer studio that's crapping out.
>> 
>> 
>> On 6/28/2016 12:23 PM, Quinn Stevenson wrote:
>>> Hmmm…  I just ran the unit test using this XML again, and I’m not seeing any errors.  What version of Camel are you using?
>>> 
>>>> On Jun 28, 2016, at 10:21 AM, Thomas Hehl <th...@heavyweightsoftware.com> wrote:
>>>> 
>>>> I cannot get your XML to parse. It's throwing exceptions.
>>>> 
>>>> 
>>>> On 6/28/2016 11:57 AM, Quinn Stevenson wrote:
>>>>>  <bean id="test-broker" class="org.apache.activemq.camel.component.ActiveMQComponent">
>>>>>         <property name="brokerURL" value="vm://embedded-broker?create=false"/>
>>>>>     </bean>
>>>>> 
>>>>>     <camel:camelContext id="blueprint-request-response-context" xmlns="http://camel.apache.org/schema/blueprint">
>>>>>         <route id="jms-request-response">
>>>>>             <from uri="direct://trigger" />
>>>>>             <to uri="test-broker://queue:testQueue?useMessageIDAsCorrelationID=true" pattern="InOut"/>
>>>>>             <log message="Response: ${body}" />
>>>>>             <to uri="mock://target"/>
>>>>>         </route>
>>>>>     </camel:camelContext>
>>>>> </blueprint>
>> 
> 


Re: Blueprint request/reply pattern

Posted by Thomas Hehl <th...@heavyweightsoftware.com>.
What version are you running, Quinn?


On 6/28/2016 12:26 PM, Thomas Hehl wrote:
> JBoss Developer Studio
>
> Version: 8.1.0.GA
> Build id: GA-v20150327-1349-B467
> Build date: 20150327-1349
>
> Apache Camel 2.15.1.redhat-621084
>
> It's the developer studio that's crapping out.
>
>
> On 6/28/2016 12:23 PM, Quinn Stevenson wrote:
>> Hmmm\u2026  I just ran the unit test using this XML again, and I\u2019m not 
>> seeing any errors.  What version of Camel are you using?
>>
>>> On Jun 28, 2016, at 10:21 AM, Thomas Hehl 
>>> <th...@heavyweightsoftware.com> wrote:
>>>
>>> I cannot get your XML to parse. It's throwing exceptions.
>>>
>>>
>>> On 6/28/2016 11:57 AM, Quinn Stevenson wrote:
>>>>   <bean id="test-broker" 
>>>> class="org.apache.activemq.camel.component.ActiveMQComponent">
>>>>          <property name="brokerURL" 
>>>> value="vm://embedded-broker?create=false"/>
>>>>      </bean>
>>>>
>>>>      <camel:camelContext id="blueprint-request-response-context" 
>>>> xmlns="http://camel.apache.org/schema/blueprint">
>>>>          <route id="jms-request-response">
>>>>              <from uri="direct://trigger" />
>>>>              <to 
>>>> uri="test-broker://queue:testQueue?useMessageIDAsCorrelationID=true" 
>>>> pattern="InOut"/>
>>>>              <log message="Response: ${body}" />
>>>>              <to uri="mock://target"/>
>>>>          </route>
>>>>      </camel:camelContext>
>>>> </blueprint>
>


Re: Blueprint request/reply pattern

Posted by Thomas Hehl <th...@heavyweightsoftware.com>.
JBoss Developer Studio

Version: 8.1.0.GA
Build id: GA-v20150327-1349-B467
Build date: 20150327-1349

Apache Camel 2.15.1.redhat-621084

It's the developer studio that's crapping out.


On 6/28/2016 12:23 PM, Quinn Stevenson wrote:
> Hmmm\u2026  I just ran the unit test using this XML again, and I\u2019m not seeing any errors.  What version of Camel are you using?
>
>> On Jun 28, 2016, at 10:21 AM, Thomas Hehl <th...@heavyweightsoftware.com> wrote:
>>
>> I cannot get your XML to parse. It's throwing exceptions.
>>
>>
>> On 6/28/2016 11:57 AM, Quinn Stevenson wrote:
>>>   <bean id="test-broker" class="org.apache.activemq.camel.component.ActiveMQComponent">
>>>          <property name="brokerURL" value="vm://embedded-broker?create=false"/>
>>>      </bean>
>>>
>>>      <camel:camelContext id="blueprint-request-response-context" xmlns="http://camel.apache.org/schema/blueprint">
>>>          <route id="jms-request-response">
>>>              <from uri="direct://trigger" />
>>>              <to uri="test-broker://queue:testQueue?useMessageIDAsCorrelationID=true" pattern="InOut"/>
>>>              <log message="Response: ${body}" />
>>>              <to uri="mock://target"/>
>>>          </route>
>>>      </camel:camelContext>
>>> </blueprint>


Re: Blueprint request/reply pattern

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
Hmmm…  I just ran the unit test using this XML again, and I’m not seeing any errors.  What version of Camel are you using?

> On Jun 28, 2016, at 10:21 AM, Thomas Hehl <th...@heavyweightsoftware.com> wrote:
> 
> I cannot get your XML to parse. It's throwing exceptions.
> 
> 
> On 6/28/2016 11:57 AM, Quinn Stevenson wrote:
>>  <bean id="test-broker" class="org.apache.activemq.camel.component.ActiveMQComponent">
>>         <property name="brokerURL" value="vm://embedded-broker?create=false"/>
>>     </bean>
>> 
>>     <camel:camelContext id="blueprint-request-response-context" xmlns="http://camel.apache.org/schema/blueprint">
>>         <route id="jms-request-response">
>>             <from uri="direct://trigger" />
>>             <to uri="test-broker://queue:testQueue?useMessageIDAsCorrelationID=true" pattern="InOut"/>
>>             <log message="Response: ${body}" />
>>             <to uri="mock://target"/>
>>         </route>
>>     </camel:camelContext>
>> </blueprint>
> 


Re: Blueprint request/reply pattern

Posted by Thomas Hehl <th...@heavyweightsoftware.com>.
I cannot get your XML to parse. It's throwing exceptions.


On 6/28/2016 11:57 AM, Quinn Stevenson wrote:
>   <bean id="test-broker" class="org.apache.activemq.camel.component.ActiveMQComponent">
>          <property name="brokerURL" value="vm://embedded-broker?create=false"/>
>      </bean>
>
>      <camel:camelContext id="blueprint-request-response-context" xmlns="http://camel.apache.org/schema/blueprint">
>          <route id="jms-request-response">
>              <from uri="direct://trigger" />
>              <to uri="test-broker://queue:testQueue?useMessageIDAsCorrelationID=true" pattern="InOut"/>
>              <log message="Response: ${body}" />
>              <to uri="mock://target"/>
>          </route>
>      </camel:camelContext>
> </blueprint>


Re: Blueprint request/reply pattern

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
The only thing that looks a little off to me in the XML is the log statement.  I’m not sure why you’d get the original message - I’d expect it to be null/empty.  Maybe it is getting set somewhere else in your route?

Here’s a simple example that works for me
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:camel="http://camel.apache.org/schema/blueprint"
           xsi:schemaLocation="
         http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
         http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <bean id="test-broker" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="vm://embedded-broker?create=false"/>
    </bean>

    <camel:camelContext id="blueprint-request-response-context" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="jms-request-response">
            <from uri="direct://trigger" />
            <to uri="test-broker://queue:testQueue?useMessageIDAsCorrelationID=true" pattern="InOut"/>
            <log message="Response: ${body}" />
            <to uri="mock://target"/>
        </route>
    </camel:camelContext>
</blueprint>

And here’s a unit test for it so you can see it run
package com.pronoia.camel;

import java.util.Dictionary;
import java.util.Map;

import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.activemq.junit.EmbeddedActiveMQBroker;
import org.apache.camel.EndpointInject;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsConstants;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.apache.camel.util.KeyValueHolder;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

public class BlueprintRequestResponseTest extends CamelBlueprintTestSupport {
    @Rule
    public EmbeddedActiveMQBroker broker = new EmbeddedActiveMQBroker();

    @EndpointInject( uri = "mock://target")
    MockEndpoint target;

    @Override
    protected String getBlueprintDescriptor() {
        return "/OSGI-INF/blueprint/blueprint-request-response.xml";
    }

    @Override
    protected RoutesBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from( "test-broker://queue:testQueue")
                        .setBody().constant( "Response Message")
                        .to( "test-broker://queue://bar?exchangePattern=InOnly")
                        ;

            }
        };
    }

    @Test
    public void testRoute() throws Exception {
        target.expectedBodiesReceived("Response Message");

        template.sendBody("direct://trigger", "Trigger Message");

        assertMockEndpointsSatisfied();
    }

}



> On Jun 28, 2016, at 2:43 AM, Thomas Hehl <th...@heavyweightsoftware.com> wrote:
> 
> Please see my question regarding Active MQ request/reply here: http://stackoverflow.com/questions/38060148/trying-to-capture-response-from-activemq-in-my-camel-route
> 
> Thanks!
> 
>