You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by pratibhaG <pr...@in2m.com> on 2008/05/27 07:54:58 UTC
How to route message from a listener?
Hi,
How can I retrieve the in message from message exchange?
I have following code
public class ExceptionListenerService implements ExchangeListener {
public void exchangeAccepted(ExchangeEvent event) {
// TODO Auto-generated method stub
}
public void exchangeSent(ExchangeEvent event) {
MessageExchange me = event.getExchange();
System.out.println("in listener: message is= " + me);
}
}
The output is as follows:
in listener: message is= InOnly[
id: ID:192.168.2.64-11a28d65e8f-4:0
status: Error
role: provider
endpoint: providerEndpoint
in: <?xml version="1.0" encoding="UTF-8"?><Request>
<service name="updatepassword">
<parameter name="username">sandeep37</parameter>
<parameter name="password">password</parameter>
</service>
</Request>
error: java.net.ConnectException: Connection refused
]
I want to retrieve the message in message '<?xml version="1.0"
encoding="UTF-8"?><Request>
<service name="updatepassword">
<parameter name="username">sandeep37</parameter>
<parameter name="password">password</parameter>
</service>
</Request>'
How can I retrieve it?
I tried me.getMessage("in") and me.getMessage("in").getContent(), but it
does not serve the purpose.
Please help!
-Pratibha
--
View this message in context: http://www.nabble.com/How-to-route-message-from-a-listener--tp17483535p17483535.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to route message from a listener?
Posted by pratibhaG <pr...@in2m.com>.
i am facing a 3 problems
1)to convert my string message in MessageExchange.
2)send the MessageExhange object to service MyErrorhandlerservice
If you help me to solve these problems I think I can archive what I need.
Pratibha
--
View this message in context: http://www.nabble.com/How-to-route-message-from-a-listener--tp17483625p17528391.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to route message from a listener?
Posted by pratibhaG <pr...@in2m.com>.
I also have to deal with JBI errors. Suppose I am trying to send message from
app1 to app2, but my app2 is down. In this case I will get
"java.net.ConnectException: Connection refused" and the message status will
change to ERROR.
So my listener should handle both the cases.
If I use camel I have to tap messages from each and every path by explicitly
configuring it. If my applications go on increasing it will be difficult to
maintain.
Let me explain the flow in both the cases:
1)Listener will listen to all the messages on NMR
2)app1 sends message to app2 say <request><user>hello</user></request>
3)
Case1: app2 responds with success
The response is <response><status>success</status></response>
errorListener has nothing to do.
case2: app2 responds with error
The response is
<response><status>error</status><description>Invalid
user</description></response>
errorListener takes the "in" message
<request><message>hello</message></request> as well as "out" message from
app2
<response><status>error</status><description>InvalidUser</description></response>
append them and send message
<errorMessage><request><user>hello</user></request><response><status>error</status><description>Invalid
user</description></response></errorMessage>
to service " {http://servicemix.abc.com/samples/http}MyErrorHandlingService
"with endpoint "errorHandlerProviderEndpoint"
case3: app2 is DOWN
The message status will change to error. There will be error
message java.net.ConnectException: Connection refused on NMR.
Listener will get the "in" message as well as "error" message
"java.net.ConnectException: Connection refused" create a message like this
<errorMessage><request><user>hello</user></request><error><description>java.net.ConnectException:
Connection refused</description></rerror></errorMessage> to service "
{http://servicemix.abc.com/samples/http}MyErrorHandlingService "with
endpoint "errorHandlerProviderEndpoint"
i am done with creating the messages that I have to send to the
errorhandling service in string format. I am stuck on how to send them to
ErrorHandlingService
How can I send message like this
whic<errorMessage><request><user>hello</user></request><error><description>java.net.ConnectException:
Connection refused</description></rerror></errorMessage>
which is in string format to ErrorHandlingService?
--
View this message in context: http://www.nabble.com/How-to-route-message-from-a-listener--tp17483625p17528001.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to route message from a listener?
Posted by Bruce Snyder <br...@gmail.com>.
On Wed, May 28, 2008 at 10:27 PM, pratibhaG <pr...@in2m.com> wrote:
>
> Why did you suggest to use use that when the exchange is sent by the consumer
> the first time. Because in my case it will be different.
> I also have to use it when message is sent by provider.
> The message is like this
>
> 1)Listener will listen to all the messages on NMR
> 2)app1 sends message to app2 say <request><message>hello</message></request>
> 3)app2 will respond with either success or error
> The response can be <response><status>success</status></response> or it can
> be <response><status>error</status></response>
> Now my listener should take the "in" message as well as "out" message from
> app2 append them and send the appended message to the Error handler for
> further processing.
>
> that is listener should send message
> <message><request><message>hello</message></request><response><status>error</status></response></message>
> to service " {http://servicemix.abc.com/samples/http}MyErrorHandlingService
> "with endpoint "errorHandlerProviderEndpoint"
>
> I have achieved the message
> <message><request><message>hello</message></request><response><status>error</status></response></message>
>
> Now how to send it?
I had no idea the error to which you have been referring all this time
is not actually a JBI error - it's simply just an error within the
content of the normalized message!
This being the case, stop trying to handle all of this using the
exception listener I provided. Instead, just route the message through
a content-based router using either the servicemix-eip component or
the servicemix-camel component. This will allow you to test the
content of the normalized message and determine routing based on the
content.
Bruce
--
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'
Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/
Apache Geronimo - http://geronimo.apache.org/
Blog: http://bruceblog.org/
Re: How to route message from a listener?
Posted by pratibhaG <pr...@in2m.com>.
Why did you suggest to use use that when the exchange is sent by the consumer
the first time. Because in my case it will be different.
I also have to use it when message is sent by provider.
The message is like this
1)Listener will listen to all the messages on NMR
2)app1 sends message to app2 say <request><message>hello</message></request>
3)app2 will respond with either success or error
The response can be <response><status>success</status></response> or it can
be <response><status>error</status></response>
Now my listener should take the "in" message as well as "out" message from
app2 append them and send the appended message to the Error handler for
further processing.
that is listener should send message
<message><request><message>hello</message></request><response><status>error</status></response></message>
to service " {http://servicemix.abc.com/samples/http}MyErrorHandlingService
"with endpoint "errorHandlerProviderEndpoint"
I have achieved the message
<message><request><message>hello</message></request><response><status>error</status></response></message>
Now how to send it?
Pratibha
--
View this message in context: http://www.nabble.com/How-to-route-message-from-a-listener--tp17483625p17527388.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to route message from a listener?
Posted by Guillaume Nodet <gn...@gmail.com>.
Yes, it should work, though I haven't tested it. Make sure to only use
that when the exchange is sent by the consumer the first time. To
retrieve ServiceEndpoint, you can use the JBIContainer and access the
registry of endpoints. Your listener can implement the
org.apache.servicemix.jbi.event.ContainerAware interface so that it is
injected a reference to the JBI container, then you should be able to
do the following:
EndpointRegistry registry = container.getRegistry().getEndpointRegistry();
The endpoint registry contains lots of methods to query for endpoints.
On Wed, May 28, 2008 at 1:41 PM, pratibhaG <pr...@in2m.com> wrote:
>
> Suppose in my listener i have
> public void exchangeSent(ExchangeEvent event){
> MessageExchange me = event.getExchange();
> }
> then can I use me.setEndpoint(ServiceEndPoint arg) to change my route and
> send it to my destination?
> If I can use how to create ServiceEndPoint?
>
> -Pratibha
> --
> View this message in context: http://www.nabble.com/How-to-route-message-from-a-listener--tp17483625p17510752.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>
--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
Re: How to route message from a listener?
Posted by pratibhaG <pr...@in2m.com>.
Suppose in my listener i have
public void exchangeSent(ExchangeEvent event){
MessageExchange me = event.getExchange();
}
then can I use me.setEndpoint(ServiceEndPoint arg) to change my route and
send it to my destination?
If I can use how to create ServiceEndPoint?
-Pratibha
--
View this message in context: http://www.nabble.com/How-to-route-message-from-a-listener--tp17483625p17510752.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to route message from a listener?
Posted by pratibhaG <pr...@in2m.com>.
I dropped the idea to use camel for error handling.
I am creating an Error Listener as well as Error handler.
Suppose I have my in message like <request>abc</request>
I want to send the message as
<message><request>abc</request><error>someError</error></message>
How can to use MessageExhange and send it to some destination as I said in
previous message?
Do you have any example which does this?
-Pratibha
--
View this message in context: http://www.nabble.com/How-to-route-message-from-a-listener--tp17483625p17510478.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Re: How to route message from a listener?
Posted by Gert Vanthienen <ge...@skynet.be>.
Prathiba,
As Guillaume explained to you before, you can not re-route a message
exchange from an exchange listener. You can start a new, second
MessageExchange and send that to your error queue. You can also achieve
something similar with a Camel deadletterchannel, as you have been doing
before.
You can get to the 'in' normalized message with
exchange.getMessage('in'). This Normalized message's content can be
accessed with getContent(), so the code you are showing us here is
essentially correct. Be aware that the message content is an XML Source
though, if you want to access it as a String, you can use ServiceMix'
SourceTransformer to get that done.
Regards,
Gert
pratibhaG wrote:
> Hi,
> How can I retrieve the in message from message exchange?
>
> I have following code
> public class ExceptionListenerService implements ExchangeListener {
>
> public void exchangeAccepted(ExchangeEvent event) {
> // TODO Auto-generated method stub
> }
> public void exchangeSent(ExchangeEvent event) {
> MessageExchange me = event.getExchange();
> System.out.println("in listener: message is= " + me);
> }
> }
>
> The output is as follows:
> in listener: message is= InOnly[
> id: ID:192.168.2.64-11a28d65e8f-4:0
> status: Error
> role: provider
> endpoint: providerEndpoint
> in: <?xml version="1.0" encoding="UTF-8"?><Request>
> <service name="updatepassword">
> <parameter name="username">sandeep37</parameter>
> <parameter name="password">password</parameter>
> </service>
> </Request>
> error: java.net.ConnectException: Connection refused
> ]
>
>
> I want to retrieve the message in message '<?xml version="1.0"
> encoding="UTF-8"?><Request>
> <service name="updatepassword">
> <parameter name="username">sandeep37</parameter>
> <parameter name="password">password</parameter>
> </service>
> </Request>'
>
> How can I retrieve it?
> I tried me.getMessage("in") and me.getMessage("in").getContent(), but it
> does not serve the purpose.
>
> Please help!
>
> -Pratibha
>