You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "alessandro.cangini" <th...@hotmail.com> on 2010/07/05 13:34:11 UTC

XMPP Component Questions

Greetings,

I'll explain my problem shortly, i'm currently working on a project that
uses apache servicemix and apache camel for routing messages, now i'm
working on the XMPP-related stuff and i have some problems (please forgive
my slightly incompetence)

1) configuring the route in the usual method i am unable to specify
different destinations (i.e. in my project i should be able to retrieve
messages from an XMPP port (and it goes well with the URI
from("xmpp://XMPPConsumer?password=xxxx") , note that i'll use two
components (a consumer named systemrx and a producer named systemtx) because
i have choice about this (it is an academic project))

the problem is when i want to send the message to the correct address
because the route is builded when camel context starts (for example setting
a uri like this //.to("xmpp://XMPPProducer/SomeReceiver?password=xxxx");
Specifing the receiver it works well, but i want to change the receiver, now
i have  two possibile solutions

1) Create a route each time i receive a message, (i receive the message,
extract the destination from message body, istantiate the component an then
send)

2) have a dynamic route like this (is this possibile?)
from("xmpp://XMPPConsumer?password=xxxx").process(SomeProcess).toF("xmpp://XMPPConsumer/%s?password=xxxx",destination);
(destination should be setted in SomeProcess)
(reading the manual i discovered that XMPP component supports headers only
for In Messages, (i suggest that setting a "participant" header for the
outgoing message could do the trick but i don't know if this is possible)

otherwise are possibile any other solutions that i don't know? 
thanks for advice, any help would be greatly appreciated

Alessandro
-- 
View this message in context: http://camel.465427.n5.nabble.com/XMPP-Component-Questions-tp696503p696503.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: XMPP Component Questions

Posted by Claus Ibsen <cl...@gmail.com>.
You need to install the camel-xmpp feature in SMX

See the SMX guides here
http://fusesource.com/products/enterprise-servicemix4/#documentation
Also the OSGi guide etc.





On Tue, Jul 6, 2010 at 12:51 PM, alessandro.cangini
<th...@hotmail.com> wrote:
>
> Thank you very much for the hint
>
> by the way it seems to be unapplicable in my case because i have to work on
> apache servicemix and i have some problems, appearently i have to build my
> route only with a routeBuilder because the servicemix-camel-service-unit
> maven archetype only gives a routeBuilder for  JAVA DSL routing definitions
> and a camelcontext.xml  for a XML-like definition, using the first one i can
> get the Camel Context and creating the producer
>
> class MyRouteBuilder extends RouteBuilder {
> private CamelContext camel = this.getContext();
> private ProducerTemplate producer = camel.createProducerTemplate();
> ...
> public void configure() throws Exception {
>   ...
>  }
>
> class OutputTransformer implements Processor {
>   // creating URI
>   //creating message body
>   producer.sendBody(uri,sbody);
>
>  }
> }
>
>
> but in my processor when i try to send to selected uri
>
> producer.sendBody(uri,sbody);
>
> it gives the following Exception
> org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint:
> xmpp://myProducer/Destination?password=xxxx due to: No component found with
> scheme: xmpp
>
> and in servicemix i don't know how to create The Desired Endpoint, the usual
> way seems to be unapplicable
> (camelContext.addComponent("xmpp",XMPPComponent)) because the camel-xmpp
> component is inside an OSGI enviroment (servicemix 4.2.0)) and i have a lack
> of knowledge about this
>
> Does anyone have any hint about this problem?, any help would be greatly
> appreciated
> --
> View this message in context: http://camel.465427.n5.nabble.com/XMPP-Component-Questions-tp696503p876304.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: XMPP Component Questions

Posted by "alessandro.cangini" <th...@hotmail.com>.
Solved!

i have to declare the dependency to the camel-xmpp component in the pom.xml
file and this is the portion of Myprocess

String uri = "xmpp://MyProducer/"+Destination+"?password=xxxx";
XmppComponent xmpp = new XmppComponent();
if (camel.getComponent("xmpp") == null)	camel.addComponent("xmpp",xmpp);
ProducerTemplate producer = camel.createProducerTemplate();
producer.sendBody(uri,sbody);

Thank you very much!
-- 
View this message in context: http://camel.465427.n5.nabble.com/XMPP-Component-Questions-tp696503p915471.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: XMPP Component Questions

Posted by "alessandro.cangini" <th...@hotmail.com>.
Thank you very much for the hint

by the way it seems to be unapplicable in my case because i have to work on
apache servicemix and i have some problems, appearently i have to build my
route only with a routeBuilder because the servicemix-camel-service-unit
maven archetype only gives a routeBuilder for  JAVA DSL routing definitions
and a camelcontext.xml  for a XML-like definition, using the first one i can
get the Camel Context and creating the producer

class MyRouteBuilder extends RouteBuilder {
private CamelContext camel = this.getContext();
private ProducerTemplate producer = camel.createProducerTemplate();
...
public void configure() throws Exception { 
   ...
 }

class OutputTransformer implements Processor {
   // creating URI
   //creating message body
   producer.sendBody(uri,sbody);

 }
}


but in my processor when i try to send to selected uri

producer.sendBody(uri,sbody);

it gives the following Exception
org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint:
xmpp://myProducer/Destination?password=xxxx due to: No component found with
scheme: xmpp

and in servicemix i don't know how to create The Desired Endpoint, the usual
way seems to be unapplicable
(camelContext.addComponent("xmpp",XMPPComponent)) because the camel-xmpp
component is inside an OSGI enviroment (servicemix 4.2.0)) and i have a lack
of knowledge about this

Does anyone have any hint about this problem?, any help would be greatly
appreciated
-- 
View this message in context: http://camel.465427.n5.nabble.com/XMPP-Component-Questions-tp696503p876304.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: XMPP Component Questions

Posted by Евгений Лиукконен <ev...@gmail.com>.
Sorry, if I’ve understood you wrongly, but perhaps you can send messages
exactly from your processor --- SomeProcess?

Something like that:

private CamelContext camelContext; // somewhere you create a camel context
…
class SomeRoutes extends RouteBuilder {

    private ProducerTemplate producerTemplate =
camelContext.createProducerTemplate();

    @Override
    public void configure() throws Exception {
        from("xmpp://XMPPConsumer?password=xxxx").process(SomeProcess);
    }

    class SomeProcess implements Processor {
        @Override
        public void process(Exchange exchange) throws Exception {
            String destination = "d1";  //set destination the way you need
            String uri = "xmpp://XMPPProducer/" + destination +
"?password=xxxx");
            producerTemplate.sendBody(uri, "Some sort of message.");

        }
    }
}

If you are using dependency injection, you may prefer to use @Produce on
producerTemplate.

Or you can use a recipient list, especially if you want to send message to
multiple destinations. http://camel.apache.org/recipient-list.html

.....
> Alessandro
> --
> View this message in context:
http://camel.465427.n5.nabble.com/XMPP-Component-Questions-tp696503p696503.html
> Sent from the Camel - Users mailing list archive at Nabble.com.