You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by lone squirrely <th...@gmail.com> on 2011/03/04 22:03:50 UTC

Sender - Bounc Camel routes using spring config

Hey - I have tried to figure this problem out but I am still stuck!  I
am trying to write a simple program pair that will just bounce strings
around!  I have a simple "bounceService" and a simple "senderService".
 The bounceService just needs to start a activemqBroker and hookup to
some queue.  The other just connects from a different machine (or the
same...) and sends a message.  It just wants to see that back.

I am unsure if the messages are getting through.  Rather, I am pretty
sure they aren't...
If you could take a quick peek, it would be immensely helpful.



First! the bouceService:
--------------------------- SPRING APPLICATION CONTEXT
-------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:amq="http://activemq.apache.org/schema/core"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
        http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd
        http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
">

          <!--
       xmlns:broker="http://activemq.apache.org/schema/core"
           -->
  <context:component-scan base-package="com" />
  <context:property-placeholder location="classpath:properties/*.properties" />

  <bean id="bounceService" class="com.service.BounceService">
     <constructor-arg index="0"><ref bean="testCamelContext"
/></constructor-arg>
  </bean>

  <camel:camelContext id="testCamelContext">
    <!--
    <camel:package>com.camel</camel:package>
    -->
    <camel:route id="SIMPLE_BOUNCE">
      <camel:description>
        Takes a message from the amq broker and puts turns it back around.
      </camel:description>
      <camel:from uri="activemq:test:bounce" />
      <camel:bean ref="bounceService" method="bounceString" />
    </camel:route>
  </camel:camelContext>

  <!-- Setup a broker for testing -->
      <!--
      <amq:transportConnector name="stomp" uri="tcp://localhost:61613" />
      -->
  <amq:broker persistent="false">
    <amq:transportConnectors>
      <amq:transportConnector name="openWire" uri="tcp://localhost:9091" />
    </amq:transportConnectors>
  </amq:broker>

  <bean id="activemqBroker"
class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:9091" />
  </bean>

  <!-- Traces flow of messages -->
  <bean id="traceFormatter"
class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
    <property name="showBody" value="false" />
    <property name="showBodyType" value="true" />
    <property name="showBreadCrumb" value="false" />
    <property name="maxChars" value="1000" />
  </bean>
</beans>

--------------------------------------- THE bounceService
--------------------------------------------
package com.service;

import org.apache.camel.CamelContext;
import org.apache.camel.Handler;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.Route;
import org.springframework.stereotype.Service;

@Service(value = "bounceService")
public class BounceService {

  public BounceService (CamelContext camelContext) {
    System.out.println ("***************************************");

    System.out.println ("Camel context: " + camelContext.getName ());
    for (Route r : camelContext.getRoutes ()) {
      System.out.println (r.getEndpoint ());
    }

    System.out.println ("***************************************");
  }

  @Handler
  public String bounceString (String inStr) {
    String outStr = "RET_" + inStr;

    System.out.println ("---------------- START ----------------");
    System.out.println ("Got this message: " + inStr);
    System.out.println ("Returning this message " + outStr);
    System.out.println ("----------------- END -----------------");

    return outStr;
  }
}


On to the senderService:
------------------------------------- SENDER SERVICE
SPRING----------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:amq="http://activemq.apache.org/schema/core"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
        http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd
        http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
">
  <context:component-scan base-package="com" />
  <context:property-placeholder location="classpath:properties/*.properties" />

  <bean id="senderService" class="com.service.SenderService">
     <constructor-arg index="0"><ref bean="testCamelContext"
/></constructor-arg>
  </bean>

  <camel:camelContext id="testCamelContext">
    <camel:package>com.camel</camel:package>
    <camel:route id="Timer_to_request">
      <camel:from uri="timer://testBounce?fixedRate=true&amp;period=2000" />
      <camel:to uri="bean:senderService?method=sendString" />
    </camel:route>

    <camel:route id="service_to_bounce">
      <camel:from uri="bean:senderService?method=sendString" />
      <camel:to uri="activemq:test:bounce" />
    </camel:route>
  </camel:camelContext>

  <!-- Setup a broker for testing -->
      <!--
      <amq:transportConnector name="stomp" uri="tcp://localhost:61613" />
  <amq:broker>
    <amq:transportConnectors>
      <amq:transportConnector name="openWire" uri="tcp://localhost:9091" />
    </amq:transportConnectors>
  </amq:broker>
      -->

  <bean id="activemqBroker"
class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:9091" />
  </bean>

  <!-- Traces flow of messages -->
  <bean id="traceFormatter"
class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
    <property name="showBody" value="false" />
    <property name="showBodyType" value="true" />
    <property name="showBreadCrumb" value="false" />
    <property name="maxChars" value="1000" />
  </bean>
</beans>

---------------------------------------------------- the senderService
------------------------------------------------------------------------------------------------------------------

package com.service;

import org.apache.camel.CamelContext;
import org.apache.camel.Handler;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.Route;
import org.springframework.stereotype.Service;

@Service(value = "senderService")
public class SenderService {

  public SenderService (CamelContext camelContext) {
    System.out.println ("***************************************");

    System.out.println ("Camel context: " + camelContext.getName ());
    for (Route r : camelContext.getRoutes ()) {
      System.out.println (r.getEndpoint ());
    }


    System.out.println ("***************************************");
  }

  @Handler
  public String sendString () {
    return "This is a dumb test - it should just do a round Trip...";
  }

  @Handler
  public void receiveString (String inStr) {
    System.out.println ("---------------- START ----------------");
    System.out.println ("Got this message: " + inStr);
    System.out.println ("----------------- END -----------------");
  }

  /**
   *  called by some event...that triggers the request
   */
  public void causeInteraction () {
    // some event...
    sendString ();
  }
}

The "openWire" connection seems to take: (from bounceService)
12:31:43,877  INFO TransportServerThreadSupport:72 - Listening for
connections at: tcp://northstar.appsig.com:9091
12:31:43,877  INFO TransportConnector:252 - Connector openWire Started

but i get this error (scrolling):
12:31:44,466 DEBUG SpringCamelContext:1842 - Route: SIMPLE_BOUNCE >>>
EventDrivenConsumerRoute[Endpoint[activemq://test:bounce]
->instrumentation:route[UnitOfWork(Channel[BeanProcessor[bean:
bounceService]])]]
12:31:44,466 DEBUG SpringCamelContext:1846 - Starting consumer (order:
1000) on route: SIMPLE_BOUNCE
12:31:44,474 DEBUG DefaultManagementAgent:314 - Registered MBean with
objectname: org.apache.camel:context=northstar.appsig.com/testCamelContext,type=consumers,name=JmsConsumer(0x1c90a278)
12:31:44,474 DEBUG JmsConsumer:91 - Starting consumer:
Consumer[activemq://test:bounce]
12:31:44,486 DEBUG FailoverTransport:663 - Reconnect was triggered but
transport is not started yet
. Wait for start to connect the transport.
12:31:44,495 DEBUG FailoverTransport:297 - Started.
12:31:44,496 DEBUG FailoverTransport:656 - Waking up reconnect task
12:31:44,497 DEBUG FailoverTransport:686 - urlList
connectionList:[tcp://localhost:61616]
12:31:44,499 DEBUG FailoverTransport:840 - Attempting connect to:
tcp://localhost:61616
12:31:44,503 DEBUG DefaultMessageListenerContainer:372 - Established
shared JMS Connection
12:31:44,504 DEBUG DefaultMessageListenerContainer:539 - Resumed
paused task: org.springframework.j
ms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker@64b25680
12:31:44,544 DEBUG FailoverTransport:884 - Connect fail to:
tcp://localhost:61616, reason: java.net.ConnectException: Connection
refused
12:31:44,545 DEBUG TcpTransport:508 - Stopping transport tcp://localhost:61616

I am unsure why it is trying to use localhost:61616????

And i don't see a connection in the senderService, only the timer going off...
Again any help would be great, I am pretty sure this is just
originating from my lack of knowledge.

Thanks in advance!!!

Re: Sender - Bounc Camel routes using spring config

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Mar 7, 2011 at 9:34 PM, lone squirrely
<th...@gmail.com> wrote:
> Thank you for pointing this out (and for the tutorial!).  I get so
> lost in the documentation for spring and camel.
>
> I now have both my server and client building and coming up.  I
> (think) i see them get a ref to the AMQ Broker but what I don't see is
> the run happening.
>
> I took the client in the tutorial and just put essentially a run on it
> - it just intermittently sends a msg.  I bundled this up into a war
> and deployed it out to tomcat.  What I am not seeing happen is the
> "main" get called.  Is there some way that I can specify what to run,
> to start the service?
>

See this page
http://camel.apache.org/tutorial-on-using-camel-in-a-web-application.html


> On Fri, Mar 4, 2011 at 11:15 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> There is this JMS tutorial which has a client and server and sends data to/from
>> http://camel.apache.org/tutorial-jmsremoting.html
>>
>> In your example you use "activemq" as scheme in your Camel routes.
>>
>> And when you do that, then your ActiveMQComponent <bean> should have
>> the same id.
>> In one of your XML files it does not.
>>
>> That mean Camel will use the default AMQComponent (with default
>> settings) which happens to be available since you embedded a local AMQ
>> broker as well. So that's why it tries port 61616 which is the default
>> port.
>>
>>
>> On Fri, Mar 4, 2011 at 10:03 PM, lone squirrely
>> <th...@gmail.com> wrote:
>>> Hey - I have tried to figure this problem out but I am still stuck!  I
>>> am trying to write a simple program pair that will just bounce strings
>>> around!  I have a simple "bounceService" and a simple "senderService".
>>>  The bounceService just needs to start a activemqBroker and hookup to
>>> some queue.  The other just connects from a different machine (or the
>>> same...) and sends a message.  It just wants to see that back.
>>>
>>> I am unsure if the messages are getting through.  Rather, I am pretty
>>> sure they aren't...
>>> If you could take a quick peek, it would be immensely helpful.
>>>
>>>
>>>
>>> First! the bouceService:
>>> --------------------------- SPRING APPLICATION CONTEXT
>>> -------------------------------------
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <beans xmlns="http://www.springframework.org/schema/beans"
>>>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>       xmlns:context="http://www.springframework.org/schema/context"
>>>       xmlns:camel="http://camel.apache.org/schema/spring"
>>>       xmlns:amq="http://activemq.apache.org/schema/core"
>>>       xmlns:p="http://www.springframework.org/schema/p"
>>>       xsi:schemaLocation="
>>>        http://www.springframework.org/schema/beans
>>> http://www.springframework.org/schema/beans/spring-beans.xsd
>>>        http://www.springframework.org/schema/context
>>> http://www.springframework.org/schema/context/spring-context.xsd
>>>        http://activemq.apache.org/schema/core
>>> http://activemq.apache.org/schema/core/activemq-core.xsd
>>>        http://camel.apache.org/schema/spring
>>> http://camel.apache.org/schema/spring/camel-spring.xsd
>>> ">
>>>
>>>          <!--
>>>       xmlns:broker="http://activemq.apache.org/schema/core"
>>>           -->
>>>  <context:component-scan base-package="com" />
>>>  <context:property-placeholder location="classpath:properties/*.properties" />
>>>
>>>  <bean id="bounceService" class="com.service.BounceService">
>>>     <constructor-arg index="0"><ref bean="testCamelContext"
>>> /></constructor-arg>
>>>  </bean>
>>>
>>>  <camel:camelContext id="testCamelContext">
>>>    <!--
>>>    <camel:package>com.camel</camel:package>
>>>    -->
>>>    <camel:route id="SIMPLE_BOUNCE">
>>>      <camel:description>
>>>        Takes a message from the amq broker and puts turns it back around.
>>>      </camel:description>
>>>      <camel:from uri="activemq:test:bounce" />
>>>      <camel:bean ref="bounceService" method="bounceString" />
>>>    </camel:route>
>>>  </camel:camelContext>
>>>
>>>  <!-- Setup a broker for testing -->
>>>      <!--
>>>      <amq:transportConnector name="stomp" uri="tcp://localhost:61613" />
>>>      -->
>>>  <amq:broker persistent="false">
>>>    <amq:transportConnectors>
>>>      <amq:transportConnector name="openWire" uri="tcp://localhost:9091" />
>>>    </amq:transportConnectors>
>>>  </amq:broker>
>>>
>>>  <bean id="activemqBroker"
>>> class="org.apache.activemq.camel.component.ActiveMQComponent">
>>>    <property name="brokerURL" value="tcp://localhost:9091" />
>>>  </bean>
>>>
>>>  <!-- Traces flow of messages -->
>>>  <bean id="traceFormatter"
>>> class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
>>>    <property name="showBody" value="false" />
>>>    <property name="showBodyType" value="true" />
>>>    <property name="showBreadCrumb" value="false" />
>>>    <property name="maxChars" value="1000" />
>>>  </bean>
>>> </beans>
>>>
>>> --------------------------------------- THE bounceService
>>> --------------------------------------------
>>> package com.service;
>>>
>>> import org.apache.camel.CamelContext;
>>> import org.apache.camel.Handler;
>>> import org.apache.camel.ProducerTemplate;
>>> import org.apache.camel.Route;
>>> import org.springframework.stereotype.Service;
>>>
>>> @Service(value = "bounceService")
>>> public class BounceService {
>>>
>>>  public BounceService (CamelContext camelContext) {
>>>    System.out.println ("***************************************");
>>>
>>>    System.out.println ("Camel context: " + camelContext.getName ());
>>>    for (Route r : camelContext.getRoutes ()) {
>>>      System.out.println (r.getEndpoint ());
>>>    }
>>>
>>>    System.out.println ("***************************************");
>>>  }
>>>
>>>  @Handler
>>>  public String bounceString (String inStr) {
>>>    String outStr = "RET_" + inStr;
>>>
>>>    System.out.println ("---------------- START ----------------");
>>>    System.out.println ("Got this message: " + inStr);
>>>    System.out.println ("Returning this message " + outStr);
>>>    System.out.println ("----------------- END -----------------");
>>>
>>>    return outStr;
>>>  }
>>> }
>>>
>>>
>>> On to the senderService:
>>> ------------------------------------- SENDER SERVICE
>>> SPRING----------------------------------------
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <beans xmlns="http://www.springframework.org/schema/beans"
>>>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>       xmlns:context="http://www.springframework.org/schema/context"
>>>       xmlns:camel="http://camel.apache.org/schema/spring"
>>>       xmlns:amq="http://activemq.apache.org/schema/core"
>>>       xmlns:p="http://www.springframework.org/schema/p"
>>>       xsi:schemaLocation="
>>>        http://www.springframework.org/schema/beans
>>> http://www.springframework.org/schema/beans/spring-beans.xsd
>>>        http://www.springframework.org/schema/context
>>> http://www.springframework.org/schema/context/spring-context.xsd
>>>        http://activemq.apache.org/schema/core
>>> http://activemq.apache.org/schema/core/activemq-core.xsd
>>>        http://camel.apache.org/schema/spring
>>> http://camel.apache.org/schema/spring/camel-spring.xsd
>>> ">
>>>  <context:component-scan base-package="com" />
>>>  <context:property-placeholder location="classpath:properties/*.properties" />
>>>
>>>  <bean id="senderService" class="com.service.SenderService">
>>>     <constructor-arg index="0"><ref bean="testCamelContext"
>>> /></constructor-arg>
>>>  </bean>
>>>
>>>  <camel:camelContext id="testCamelContext">
>>>    <camel:package>com.camel</camel:package>
>>>    <camel:route id="Timer_to_request">
>>>      <camel:from uri="timer://testBounce?fixedRate=true&amp;period=2000" />
>>>      <camel:to uri="bean:senderService?method=sendString" />
>>>    </camel:route>
>>>
>>>    <camel:route id="service_to_bounce">
>>>      <camel:from uri="bean:senderService?method=sendString" />
>>>      <camel:to uri="activemq:test:bounce" />
>>>    </camel:route>
>>>  </camel:camelContext>
>>>
>>>  <!-- Setup a broker for testing -->
>>>      <!--
>>>      <amq:transportConnector name="stomp" uri="tcp://localhost:61613" />
>>>  <amq:broker>
>>>    <amq:transportConnectors>
>>>      <amq:transportConnector name="openWire" uri="tcp://localhost:9091" />
>>>    </amq:transportConnectors>
>>>  </amq:broker>
>>>      -->
>>>
>>>  <bean id="activemqBroker"
>>> class="org.apache.activemq.camel.component.ActiveMQComponent">
>>>    <property name="brokerURL" value="tcp://localhost:9091" />
>>>  </bean>
>>>
>>>  <!-- Traces flow of messages -->
>>>  <bean id="traceFormatter"
>>> class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
>>>    <property name="showBody" value="false" />
>>>    <property name="showBodyType" value="true" />
>>>    <property name="showBreadCrumb" value="false" />
>>>    <property name="maxChars" value="1000" />
>>>  </bean>
>>> </beans>
>>>
>>> ---------------------------------------------------- the senderService
>>> ------------------------------------------------------------------------------------------------------------------
>>>
>>> package com.service;
>>>
>>> import org.apache.camel.CamelContext;
>>> import org.apache.camel.Handler;
>>> import org.apache.camel.ProducerTemplate;
>>> import org.apache.camel.Route;
>>> import org.springframework.stereotype.Service;
>>>
>>> @Service(value = "senderService")
>>> public class SenderService {
>>>
>>>  public SenderService (CamelContext camelContext) {
>>>    System.out.println ("***************************************");
>>>
>>>    System.out.println ("Camel context: " + camelContext.getName ());
>>>    for (Route r : camelContext.getRoutes ()) {
>>>      System.out.println (r.getEndpoint ());
>>>    }
>>>
>>>
>>>    System.out.println ("***************************************");
>>>  }
>>>
>>>  @Handler
>>>  public String sendString () {
>>>    return "This is a dumb test - it should just do a round Trip...";
>>>  }
>>>
>>>  @Handler
>>>  public void receiveString (String inStr) {
>>>    System.out.println ("---------------- START ----------------");
>>>    System.out.println ("Got this message: " + inStr);
>>>    System.out.println ("----------------- END -----------------");
>>>  }
>>>
>>>  /**
>>>   *  called by some event...that triggers the request
>>>   */
>>>  public void causeInteraction () {
>>>    // some event...
>>>    sendString ();
>>>  }
>>> }
>>>
>>> The "openWire" connection seems to take: (from bounceService)
>>> 12:31:43,877  INFO TransportServerThreadSupport:72 - Listening for
>>> connections at: tcp://northstar.appsig.com:9091
>>> 12:31:43,877  INFO TransportConnector:252 - Connector openWire Started
>>>
>>> but i get this error (scrolling):
>>> 12:31:44,466 DEBUG SpringCamelContext:1842 - Route: SIMPLE_BOUNCE >>>
>>> EventDrivenConsumerRoute[Endpoint[activemq://test:bounce]
>>> ->instrumentation:route[UnitOfWork(Channel[BeanProcessor[bean:
>>> bounceService]])]]
>>> 12:31:44,466 DEBUG SpringCamelContext:1846 - Starting consumer (order:
>>> 1000) on route: SIMPLE_BOUNCE
>>> 12:31:44,474 DEBUG DefaultManagementAgent:314 - Registered MBean with
>>> objectname: org.apache.camel:context=northstar.appsig.com/testCamelContext,type=consumers,name=JmsConsumer(0x1c90a278)
>>> 12:31:44,474 DEBUG JmsConsumer:91 - Starting consumer:
>>> Consumer[activemq://test:bounce]
>>> 12:31:44,486 DEBUG FailoverTransport:663 - Reconnect was triggered but
>>> transport is not started yet
>>> . Wait for start to connect the transport.
>>> 12:31:44,495 DEBUG FailoverTransport:297 - Started.
>>> 12:31:44,496 DEBUG FailoverTransport:656 - Waking up reconnect task
>>> 12:31:44,497 DEBUG FailoverTransport:686 - urlList
>>> connectionList:[tcp://localhost:61616]
>>> 12:31:44,499 DEBUG FailoverTransport:840 - Attempting connect to:
>>> tcp://localhost:61616
>>> 12:31:44,503 DEBUG DefaultMessageListenerContainer:372 - Established
>>> shared JMS Connection
>>> 12:31:44,504 DEBUG DefaultMessageListenerContainer:539 - Resumed
>>> paused task: org.springframework.j
>>> ms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker@64b25680
>>> 12:31:44,544 DEBUG FailoverTransport:884 - Connect fail to:
>>> tcp://localhost:61616, reason: java.net.ConnectException: Connection
>>> refused
>>> 12:31:44,545 DEBUG TcpTransport:508 - Stopping transport tcp://localhost:61616
>>>
>>> I am unsure why it is trying to use localhost:61616????
>>>
>>> And i don't see a connection in the senderService, only the timer going off...
>>> Again any help would be great, I am pretty sure this is just
>>> originating from my lack of knowledge.
>>>
>>> Thanks in advance!!!
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: cibsen@fusesource.com
>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Sender - Bounc Camel routes using spring config

Posted by lone squirrely <th...@gmail.com>.
Thank you for pointing this out (and for the tutorial!).  I get so
lost in the documentation for spring and camel.

I now have both my server and client building and coming up.  I
(think) i see them get a ref to the AMQ Broker but what I don't see is
the run happening.

I took the client in the tutorial and just put essentially a run on it
- it just intermittently sends a msg.  I bundled this up into a war
and deployed it out to tomcat.  What I am not seeing happen is the
"main" get called.  Is there some way that I can specify what to run,
to start the service?

On Fri, Mar 4, 2011 at 11:15 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> There is this JMS tutorial which has a client and server and sends data to/from
> http://camel.apache.org/tutorial-jmsremoting.html
>
> In your example you use "activemq" as scheme in your Camel routes.
>
> And when you do that, then your ActiveMQComponent <bean> should have
> the same id.
> In one of your XML files it does not.
>
> That mean Camel will use the default AMQComponent (with default
> settings) which happens to be available since you embedded a local AMQ
> broker as well. So that's why it tries port 61616 which is the default
> port.
>
>
> On Fri, Mar 4, 2011 at 10:03 PM, lone squirrely
> <th...@gmail.com> wrote:
>> Hey - I have tried to figure this problem out but I am still stuck!  I
>> am trying to write a simple program pair that will just bounce strings
>> around!  I have a simple "bounceService" and a simple "senderService".
>>  The bounceService just needs to start a activemqBroker and hookup to
>> some queue.  The other just connects from a different machine (or the
>> same...) and sends a message.  It just wants to see that back.
>>
>> I am unsure if the messages are getting through.  Rather, I am pretty
>> sure they aren't...
>> If you could take a quick peek, it would be immensely helpful.
>>
>>
>>
>> First! the bouceService:
>> --------------------------- SPRING APPLICATION CONTEXT
>> -------------------------------------
>> <?xml version="1.0" encoding="UTF-8"?>
>> <beans xmlns="http://www.springframework.org/schema/beans"
>>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>       xmlns:context="http://www.springframework.org/schema/context"
>>       xmlns:camel="http://camel.apache.org/schema/spring"
>>       xmlns:amq="http://activemq.apache.org/schema/core"
>>       xmlns:p="http://www.springframework.org/schema/p"
>>       xsi:schemaLocation="
>>        http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans.xsd
>>        http://www.springframework.org/schema/context
>> http://www.springframework.org/schema/context/spring-context.xsd
>>        http://activemq.apache.org/schema/core
>> http://activemq.apache.org/schema/core/activemq-core.xsd
>>        http://camel.apache.org/schema/spring
>> http://camel.apache.org/schema/spring/camel-spring.xsd
>> ">
>>
>>          <!--
>>       xmlns:broker="http://activemq.apache.org/schema/core"
>>           -->
>>  <context:component-scan base-package="com" />
>>  <context:property-placeholder location="classpath:properties/*.properties" />
>>
>>  <bean id="bounceService" class="com.service.BounceService">
>>     <constructor-arg index="0"><ref bean="testCamelContext"
>> /></constructor-arg>
>>  </bean>
>>
>>  <camel:camelContext id="testCamelContext">
>>    <!--
>>    <camel:package>com.camel</camel:package>
>>    -->
>>    <camel:route id="SIMPLE_BOUNCE">
>>      <camel:description>
>>        Takes a message from the amq broker and puts turns it back around.
>>      </camel:description>
>>      <camel:from uri="activemq:test:bounce" />
>>      <camel:bean ref="bounceService" method="bounceString" />
>>    </camel:route>
>>  </camel:camelContext>
>>
>>  <!-- Setup a broker for testing -->
>>      <!--
>>      <amq:transportConnector name="stomp" uri="tcp://localhost:61613" />
>>      -->
>>  <amq:broker persistent="false">
>>    <amq:transportConnectors>
>>      <amq:transportConnector name="openWire" uri="tcp://localhost:9091" />
>>    </amq:transportConnectors>
>>  </amq:broker>
>>
>>  <bean id="activemqBroker"
>> class="org.apache.activemq.camel.component.ActiveMQComponent">
>>    <property name="brokerURL" value="tcp://localhost:9091" />
>>  </bean>
>>
>>  <!-- Traces flow of messages -->
>>  <bean id="traceFormatter"
>> class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
>>    <property name="showBody" value="false" />
>>    <property name="showBodyType" value="true" />
>>    <property name="showBreadCrumb" value="false" />
>>    <property name="maxChars" value="1000" />
>>  </bean>
>> </beans>
>>
>> --------------------------------------- THE bounceService
>> --------------------------------------------
>> package com.service;
>>
>> import org.apache.camel.CamelContext;
>> import org.apache.camel.Handler;
>> import org.apache.camel.ProducerTemplate;
>> import org.apache.camel.Route;
>> import org.springframework.stereotype.Service;
>>
>> @Service(value = "bounceService")
>> public class BounceService {
>>
>>  public BounceService (CamelContext camelContext) {
>>    System.out.println ("***************************************");
>>
>>    System.out.println ("Camel context: " + camelContext.getName ());
>>    for (Route r : camelContext.getRoutes ()) {
>>      System.out.println (r.getEndpoint ());
>>    }
>>
>>    System.out.println ("***************************************");
>>  }
>>
>>  @Handler
>>  public String bounceString (String inStr) {
>>    String outStr = "RET_" + inStr;
>>
>>    System.out.println ("---------------- START ----------------");
>>    System.out.println ("Got this message: " + inStr);
>>    System.out.println ("Returning this message " + outStr);
>>    System.out.println ("----------------- END -----------------");
>>
>>    return outStr;
>>  }
>> }
>>
>>
>> On to the senderService:
>> ------------------------------------- SENDER SERVICE
>> SPRING----------------------------------------
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <beans xmlns="http://www.springframework.org/schema/beans"
>>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>       xmlns:context="http://www.springframework.org/schema/context"
>>       xmlns:camel="http://camel.apache.org/schema/spring"
>>       xmlns:amq="http://activemq.apache.org/schema/core"
>>       xmlns:p="http://www.springframework.org/schema/p"
>>       xsi:schemaLocation="
>>        http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans.xsd
>>        http://www.springframework.org/schema/context
>> http://www.springframework.org/schema/context/spring-context.xsd
>>        http://activemq.apache.org/schema/core
>> http://activemq.apache.org/schema/core/activemq-core.xsd
>>        http://camel.apache.org/schema/spring
>> http://camel.apache.org/schema/spring/camel-spring.xsd
>> ">
>>  <context:component-scan base-package="com" />
>>  <context:property-placeholder location="classpath:properties/*.properties" />
>>
>>  <bean id="senderService" class="com.service.SenderService">
>>     <constructor-arg index="0"><ref bean="testCamelContext"
>> /></constructor-arg>
>>  </bean>
>>
>>  <camel:camelContext id="testCamelContext">
>>    <camel:package>com.camel</camel:package>
>>    <camel:route id="Timer_to_request">
>>      <camel:from uri="timer://testBounce?fixedRate=true&amp;period=2000" />
>>      <camel:to uri="bean:senderService?method=sendString" />
>>    </camel:route>
>>
>>    <camel:route id="service_to_bounce">
>>      <camel:from uri="bean:senderService?method=sendString" />
>>      <camel:to uri="activemq:test:bounce" />
>>    </camel:route>
>>  </camel:camelContext>
>>
>>  <!-- Setup a broker for testing -->
>>      <!--
>>      <amq:transportConnector name="stomp" uri="tcp://localhost:61613" />
>>  <amq:broker>
>>    <amq:transportConnectors>
>>      <amq:transportConnector name="openWire" uri="tcp://localhost:9091" />
>>    </amq:transportConnectors>
>>  </amq:broker>
>>      -->
>>
>>  <bean id="activemqBroker"
>> class="org.apache.activemq.camel.component.ActiveMQComponent">
>>    <property name="brokerURL" value="tcp://localhost:9091" />
>>  </bean>
>>
>>  <!-- Traces flow of messages -->
>>  <bean id="traceFormatter"
>> class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
>>    <property name="showBody" value="false" />
>>    <property name="showBodyType" value="true" />
>>    <property name="showBreadCrumb" value="false" />
>>    <property name="maxChars" value="1000" />
>>  </bean>
>> </beans>
>>
>> ---------------------------------------------------- the senderService
>> ------------------------------------------------------------------------------------------------------------------
>>
>> package com.service;
>>
>> import org.apache.camel.CamelContext;
>> import org.apache.camel.Handler;
>> import org.apache.camel.ProducerTemplate;
>> import org.apache.camel.Route;
>> import org.springframework.stereotype.Service;
>>
>> @Service(value = "senderService")
>> public class SenderService {
>>
>>  public SenderService (CamelContext camelContext) {
>>    System.out.println ("***************************************");
>>
>>    System.out.println ("Camel context: " + camelContext.getName ());
>>    for (Route r : camelContext.getRoutes ()) {
>>      System.out.println (r.getEndpoint ());
>>    }
>>
>>
>>    System.out.println ("***************************************");
>>  }
>>
>>  @Handler
>>  public String sendString () {
>>    return "This is a dumb test - it should just do a round Trip...";
>>  }
>>
>>  @Handler
>>  public void receiveString (String inStr) {
>>    System.out.println ("---------------- START ----------------");
>>    System.out.println ("Got this message: " + inStr);
>>    System.out.println ("----------------- END -----------------");
>>  }
>>
>>  /**
>>   *  called by some event...that triggers the request
>>   */
>>  public void causeInteraction () {
>>    // some event...
>>    sendString ();
>>  }
>> }
>>
>> The "openWire" connection seems to take: (from bounceService)
>> 12:31:43,877  INFO TransportServerThreadSupport:72 - Listening for
>> connections at: tcp://northstar.appsig.com:9091
>> 12:31:43,877  INFO TransportConnector:252 - Connector openWire Started
>>
>> but i get this error (scrolling):
>> 12:31:44,466 DEBUG SpringCamelContext:1842 - Route: SIMPLE_BOUNCE >>>
>> EventDrivenConsumerRoute[Endpoint[activemq://test:bounce]
>> ->instrumentation:route[UnitOfWork(Channel[BeanProcessor[bean:
>> bounceService]])]]
>> 12:31:44,466 DEBUG SpringCamelContext:1846 - Starting consumer (order:
>> 1000) on route: SIMPLE_BOUNCE
>> 12:31:44,474 DEBUG DefaultManagementAgent:314 - Registered MBean with
>> objectname: org.apache.camel:context=northstar.appsig.com/testCamelContext,type=consumers,name=JmsConsumer(0x1c90a278)
>> 12:31:44,474 DEBUG JmsConsumer:91 - Starting consumer:
>> Consumer[activemq://test:bounce]
>> 12:31:44,486 DEBUG FailoverTransport:663 - Reconnect was triggered but
>> transport is not started yet
>> . Wait for start to connect the transport.
>> 12:31:44,495 DEBUG FailoverTransport:297 - Started.
>> 12:31:44,496 DEBUG FailoverTransport:656 - Waking up reconnect task
>> 12:31:44,497 DEBUG FailoverTransport:686 - urlList
>> connectionList:[tcp://localhost:61616]
>> 12:31:44,499 DEBUG FailoverTransport:840 - Attempting connect to:
>> tcp://localhost:61616
>> 12:31:44,503 DEBUG DefaultMessageListenerContainer:372 - Established
>> shared JMS Connection
>> 12:31:44,504 DEBUG DefaultMessageListenerContainer:539 - Resumed
>> paused task: org.springframework.j
>> ms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker@64b25680
>> 12:31:44,544 DEBUG FailoverTransport:884 - Connect fail to:
>> tcp://localhost:61616, reason: java.net.ConnectException: Connection
>> refused
>> 12:31:44,545 DEBUG TcpTransport:508 - Stopping transport tcp://localhost:61616
>>
>> I am unsure why it is trying to use localhost:61616????
>>
>> And i don't see a connection in the senderService, only the timer going off...
>> Again any help would be great, I am pretty sure this is just
>> originating from my lack of knowledge.
>>
>> Thanks in advance!!!
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>

Re: Sender - Bounc Camel routes using spring config

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

There is this JMS tutorial which has a client and server and sends data to/from
http://camel.apache.org/tutorial-jmsremoting.html

In your example you use "activemq" as scheme in your Camel routes.

And when you do that, then your ActiveMQComponent <bean> should have
the same id.
In one of your XML files it does not.

That mean Camel will use the default AMQComponent (with default
settings) which happens to be available since you embedded a local AMQ
broker as well. So that's why it tries port 61616 which is the default
port.


On Fri, Mar 4, 2011 at 10:03 PM, lone squirrely
<th...@gmail.com> wrote:
> Hey - I have tried to figure this problem out but I am still stuck!  I
> am trying to write a simple program pair that will just bounce strings
> around!  I have a simple "bounceService" and a simple "senderService".
>  The bounceService just needs to start a activemqBroker and hookup to
> some queue.  The other just connects from a different machine (or the
> same...) and sends a message.  It just wants to see that back.
>
> I am unsure if the messages are getting through.  Rather, I am pretty
> sure they aren't...
> If you could take a quick peek, it would be immensely helpful.
>
>
>
> First! the bouceService:
> --------------------------- SPRING APPLICATION CONTEXT
> -------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>       xmlns:context="http://www.springframework.org/schema/context"
>       xmlns:camel="http://camel.apache.org/schema/spring"
>       xmlns:amq="http://activemq.apache.org/schema/core"
>       xmlns:p="http://www.springframework.org/schema/p"
>       xsi:schemaLocation="
>        http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>        http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context.xsd
>        http://activemq.apache.org/schema/core
> http://activemq.apache.org/schema/core/activemq-core.xsd
>        http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd
> ">
>
>          <!--
>       xmlns:broker="http://activemq.apache.org/schema/core"
>           -->
>  <context:component-scan base-package="com" />
>  <context:property-placeholder location="classpath:properties/*.properties" />
>
>  <bean id="bounceService" class="com.service.BounceService">
>     <constructor-arg index="0"><ref bean="testCamelContext"
> /></constructor-arg>
>  </bean>
>
>  <camel:camelContext id="testCamelContext">
>    <!--
>    <camel:package>com.camel</camel:package>
>    -->
>    <camel:route id="SIMPLE_BOUNCE">
>      <camel:description>
>        Takes a message from the amq broker and puts turns it back around.
>      </camel:description>
>      <camel:from uri="activemq:test:bounce" />
>      <camel:bean ref="bounceService" method="bounceString" />
>    </camel:route>
>  </camel:camelContext>
>
>  <!-- Setup a broker for testing -->
>      <!--
>      <amq:transportConnector name="stomp" uri="tcp://localhost:61613" />
>      -->
>  <amq:broker persistent="false">
>    <amq:transportConnectors>
>      <amq:transportConnector name="openWire" uri="tcp://localhost:9091" />
>    </amq:transportConnectors>
>  </amq:broker>
>
>  <bean id="activemqBroker"
> class="org.apache.activemq.camel.component.ActiveMQComponent">
>    <property name="brokerURL" value="tcp://localhost:9091" />
>  </bean>
>
>  <!-- Traces flow of messages -->
>  <bean id="traceFormatter"
> class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
>    <property name="showBody" value="false" />
>    <property name="showBodyType" value="true" />
>    <property name="showBreadCrumb" value="false" />
>    <property name="maxChars" value="1000" />
>  </bean>
> </beans>
>
> --------------------------------------- THE bounceService
> --------------------------------------------
> package com.service;
>
> import org.apache.camel.CamelContext;
> import org.apache.camel.Handler;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.Route;
> import org.springframework.stereotype.Service;
>
> @Service(value = "bounceService")
> public class BounceService {
>
>  public BounceService (CamelContext camelContext) {
>    System.out.println ("***************************************");
>
>    System.out.println ("Camel context: " + camelContext.getName ());
>    for (Route r : camelContext.getRoutes ()) {
>      System.out.println (r.getEndpoint ());
>    }
>
>    System.out.println ("***************************************");
>  }
>
>  @Handler
>  public String bounceString (String inStr) {
>    String outStr = "RET_" + inStr;
>
>    System.out.println ("---------------- START ----------------");
>    System.out.println ("Got this message: " + inStr);
>    System.out.println ("Returning this message " + outStr);
>    System.out.println ("----------------- END -----------------");
>
>    return outStr;
>  }
> }
>
>
> On to the senderService:
> ------------------------------------- SENDER SERVICE
> SPRING----------------------------------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>       xmlns:context="http://www.springframework.org/schema/context"
>       xmlns:camel="http://camel.apache.org/schema/spring"
>       xmlns:amq="http://activemq.apache.org/schema/core"
>       xmlns:p="http://www.springframework.org/schema/p"
>       xsi:schemaLocation="
>        http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>        http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context.xsd
>        http://activemq.apache.org/schema/core
> http://activemq.apache.org/schema/core/activemq-core.xsd
>        http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd
> ">
>  <context:component-scan base-package="com" />
>  <context:property-placeholder location="classpath:properties/*.properties" />
>
>  <bean id="senderService" class="com.service.SenderService">
>     <constructor-arg index="0"><ref bean="testCamelContext"
> /></constructor-arg>
>  </bean>
>
>  <camel:camelContext id="testCamelContext">
>    <camel:package>com.camel</camel:package>
>    <camel:route id="Timer_to_request">
>      <camel:from uri="timer://testBounce?fixedRate=true&amp;period=2000" />
>      <camel:to uri="bean:senderService?method=sendString" />
>    </camel:route>
>
>    <camel:route id="service_to_bounce">
>      <camel:from uri="bean:senderService?method=sendString" />
>      <camel:to uri="activemq:test:bounce" />
>    </camel:route>
>  </camel:camelContext>
>
>  <!-- Setup a broker for testing -->
>      <!--
>      <amq:transportConnector name="stomp" uri="tcp://localhost:61613" />
>  <amq:broker>
>    <amq:transportConnectors>
>      <amq:transportConnector name="openWire" uri="tcp://localhost:9091" />
>    </amq:transportConnectors>
>  </amq:broker>
>      -->
>
>  <bean id="activemqBroker"
> class="org.apache.activemq.camel.component.ActiveMQComponent">
>    <property name="brokerURL" value="tcp://localhost:9091" />
>  </bean>
>
>  <!-- Traces flow of messages -->
>  <bean id="traceFormatter"
> class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
>    <property name="showBody" value="false" />
>    <property name="showBodyType" value="true" />
>    <property name="showBreadCrumb" value="false" />
>    <property name="maxChars" value="1000" />
>  </bean>
> </beans>
>
> ---------------------------------------------------- the senderService
> ------------------------------------------------------------------------------------------------------------------
>
> package com.service;
>
> import org.apache.camel.CamelContext;
> import org.apache.camel.Handler;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.Route;
> import org.springframework.stereotype.Service;
>
> @Service(value = "senderService")
> public class SenderService {
>
>  public SenderService (CamelContext camelContext) {
>    System.out.println ("***************************************");
>
>    System.out.println ("Camel context: " + camelContext.getName ());
>    for (Route r : camelContext.getRoutes ()) {
>      System.out.println (r.getEndpoint ());
>    }
>
>
>    System.out.println ("***************************************");
>  }
>
>  @Handler
>  public String sendString () {
>    return "This is a dumb test - it should just do a round Trip...";
>  }
>
>  @Handler
>  public void receiveString (String inStr) {
>    System.out.println ("---------------- START ----------------");
>    System.out.println ("Got this message: " + inStr);
>    System.out.println ("----------------- END -----------------");
>  }
>
>  /**
>   *  called by some event...that triggers the request
>   */
>  public void causeInteraction () {
>    // some event...
>    sendString ();
>  }
> }
>
> The "openWire" connection seems to take: (from bounceService)
> 12:31:43,877  INFO TransportServerThreadSupport:72 - Listening for
> connections at: tcp://northstar.appsig.com:9091
> 12:31:43,877  INFO TransportConnector:252 - Connector openWire Started
>
> but i get this error (scrolling):
> 12:31:44,466 DEBUG SpringCamelContext:1842 - Route: SIMPLE_BOUNCE >>>
> EventDrivenConsumerRoute[Endpoint[activemq://test:bounce]
> ->instrumentation:route[UnitOfWork(Channel[BeanProcessor[bean:
> bounceService]])]]
> 12:31:44,466 DEBUG SpringCamelContext:1846 - Starting consumer (order:
> 1000) on route: SIMPLE_BOUNCE
> 12:31:44,474 DEBUG DefaultManagementAgent:314 - Registered MBean with
> objectname: org.apache.camel:context=northstar.appsig.com/testCamelContext,type=consumers,name=JmsConsumer(0x1c90a278)
> 12:31:44,474 DEBUG JmsConsumer:91 - Starting consumer:
> Consumer[activemq://test:bounce]
> 12:31:44,486 DEBUG FailoverTransport:663 - Reconnect was triggered but
> transport is not started yet
> . Wait for start to connect the transport.
> 12:31:44,495 DEBUG FailoverTransport:297 - Started.
> 12:31:44,496 DEBUG FailoverTransport:656 - Waking up reconnect task
> 12:31:44,497 DEBUG FailoverTransport:686 - urlList
> connectionList:[tcp://localhost:61616]
> 12:31:44,499 DEBUG FailoverTransport:840 - Attempting connect to:
> tcp://localhost:61616
> 12:31:44,503 DEBUG DefaultMessageListenerContainer:372 - Established
> shared JMS Connection
> 12:31:44,504 DEBUG DefaultMessageListenerContainer:539 - Resumed
> paused task: org.springframework.j
> ms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker@64b25680
> 12:31:44,544 DEBUG FailoverTransport:884 - Connect fail to:
> tcp://localhost:61616, reason: java.net.ConnectException: Connection
> refused
> 12:31:44,545 DEBUG TcpTransport:508 - Stopping transport tcp://localhost:61616
>
> I am unsure why it is trying to use localhost:61616????
>
> And i don't see a connection in the senderService, only the timer going off...
> Again any help would be great, I am pretty sure this is just
> originating from my lack of knowledge.
>
> Thanks in advance!!!
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/