Hi Lars,
What you're saing it's right nothing prevent to route an InOut Exchange,
but in my opinion in that case you have other better choices than drools
component.
I'm doing something similar processing, as you described and i've done
better for example with servicemix-bean than that drools.
In my opininion the original idea of the JbiHelper was to provide an
helper class, that could help user to route messages not to write
complex MEP exchange inside the route method, for this reason for me
make sense to have a class with two methods where:
1) route is used to route InOnly or RobustInOnly exchange
2) answer instead if you want to answer on the out message when an InOut
Exchage.
Andrea
Lars Heinemann ha scritto:
Andrea,
just some thoughts....
Am Mittwoch 06 August 2008 10:48:02 schrieb Andrea Zoppello:
Hi Gert,
The route method in my opinion is to handle inonly or robust inonly
exchange, if you want to answer you could use the answer method.
--> what prevents a user to not route InOut exchanges and why doesn't it makes
sense? If you use the drools as a simple router this makes imho sense.
You are right if all your processing logic is done in your drools script, then
you can just process it and send the answer.
Regards
Lars
In my opinion you must choose what you want to do when you write drools
file.
If you need to forward ( creating another exhange ) an InOnly exchange
use helper.route instead you need to use helper.answer.
This should cover all the case.
Andrea
Gert Vanthienen ha scritto:
Andrea,
Actually, I was just looking at applying that. If the code in your
last comment goes into the routeTo method, isn't this a step back from
where we were? It uses send() instead of sendSync(), but I no longer
see any possibility of handling an InOut or RobustInOnly with a Fault
message, or am I missing something there?
Regards,
Gert
Andrea Zoppello wrote:
Hi,
I had the same problem, take a look to mine last comment on
https://issues.apache.org/activemq/browse/SM-1248
Andrea
gigeril ha scritto:
Hi @ all.
I've following following setup of Servicemix:
TCP Client -----> TCP BC-->drools BC ------> TCP BC ---> TCP Server
|____>HTTP
BC -->
HTTP Server
If I connect (target Service) my own written TCP BC to the HTTP BC
or the
TCP BC it works fine (sync, async, Pattern: Inout, InOnly).
I get a problem if the drools engine get into the message chain.
Then I only
can send 23 Messages (always 23!!) until my tcp client reports me a
connection timeout and the connectors get stuck. I can only press
STRG+C in
the Servicemix Console Window to restart Servicemix and send 23
Messages.
This sending of this 23 Messages work fine. They take the way I
defined in
my .drl where it depends on the message content if it is send to the
tcp or
the http server. I also get the response back to the client.
This is the output when I press STRG+C. This whole stacktrace is
printed out
23 times.
INFO - ServiceAssemblyLifeCycle - Shutting down service
assembly:
droolsrouter-sa
INFO - ServiceUnitLifeCycle - Shutting down service unit:
droolsrouter-su
INFO - ServiceUnitLifeCycle - Shutting down service unit:
httpprovider-su
INFO - ServiceUnitLifeCycle - Shutting down service unit:
tcpconsumer-su
INFO - ServiceUnitLifeCycle - Shutting down service unit:
tcpprovider-su
INFO - JBIContainer - ServiceMix JBI Container
(ServiceMix) stopped
[Fatal Error] :1:89: Content is not allowed in trailing section.
ERROR - DroolsComponent - Error processing exchange
InOut[
id: ID:10.22.20.113-11b93600c6f-4:0
status: Active
role: provider
service: {http://knapp.com/tcphttp}myRouter
endpoint: myRouter
in: <?xml version="1.0" encoding="UTF-8"?><message
type="http"><text>hallo</text></message>
out: Unable to display: org.xml.sax.SAXParseException: Content is not
allowed in trailing section.
]
org.drools.spi.ConsequenceException:
javax.jbi.messaging.MessagingException:
java.lang.InterruptedException
at
org.drools.base.DefaultConsequenceExceptionHandler.handleException(Defa
ultConsequenceExceptionHandler.java:13
)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:558)
at
org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:518)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMem
ory.java:475)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMem
ory.java:439)
at
org.apache.servicemix.drools.DroolsEndpoint.drools(DroolsEndpoint.java:
183)
at
org.apache.servicemix.drools.DroolsEndpoint.process(DroolsEndpoint.java
:177)
at
org.apache.servicemix.common.AsyncBaseLifeCycle.doProcess(AsyncBaseLife
Cycle.java:597)
at
org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBa
seLifeCycle.java:548)
at
org.apache.servicemix.common.AsyncBaseLifeCycle.onMessageExchange(Async
BaseLifeCycle.java:502)
at
org.apache.servicemix.common.SyncLifeCycleWrapper.onMessageExchange(Syn
cLifeCycleWrapper.java:60)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(
DeliveryChannelImpl.java:610)
at
org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.
java:172)
at
org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.jav
a:168)
at
org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:
134)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecut
or.java:885)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.j
ava:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.jbi.messaging.MessagingException:
java.lang.InterruptedException
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(Delive
ryChannelImpl.java:498)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(Delive
ryChannelImpl.java:442)
at
org.apache.servicemix.common.EndpointDeliveryChannel.sendSync(EndpointD
eliveryChannel.java:102)
at
org.apache.servicemix.drools.model.JbiHelper.routeTo(JbiHelper.java:151
)
at
org.apache.servicemix.drools.model.JbiHelper.route(JbiHelper.java:109)
at
org.apache.servicemix.drools.Rule_tcphttp_http_0.consequence(Rule_tcpht
tp_http_0.java:14)
at
org.apache.servicemix.drools.Rule_tcphttp_http_0ConsequenceInvoker.eval
uate(Rule_tcphttp_http_0ConsequenceInv
oker.java:20)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:554)
... 16 more
Caused by: java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.waitForExchange
(DeliveryChannelImpl.java:699)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(Delive
ryChannelImpl.java:472)
... 23 more
ERROR - DroolsComponent - Error setting exchange
status to
ERROR
java.lang.IllegalStateException: component is not owner when trying
to set
error: org.drools.spi.ConsequenceException: j
avax.jbi.messaging.MessagingException: java.lang.InterruptedException
at
org.apache.servicemix.jbi.messaging.MessageExchangeImpl.setError(Messag
eExchangeImpl.java:264)
at
org.apache.servicemix.common.AsyncBaseLifeCycle.onMessageExchange(Async
BaseLifeCycle.java:516)
at
org.apache.servicemix.common.SyncLifeCycleWrapper.onMessageExchange(Syn
cLifeCycleWrapper.java:60)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(
DeliveryChannelImpl.java:610)
at
org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.
java:172)
at
org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.jav
a:168)
at
org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:
134)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecut
or.java:885)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.j
ava:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.drools.spi.ConsequenceException:
javax.jbi.messaging.MessagingException: java.lang.InterruptedException
at
org.drools.base.DefaultConsequenceExceptionHandler.handleException(Defa
ultConsequenceExceptionHandler.java:13
)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:558)
at
org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:518)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMem
ory.java:475)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMem
ory.java:439)
at
org.apache.servicemix.drools.DroolsEndpoint.drools(DroolsEndpoint.java:
183)
at
org.apache.servicemix.drools.DroolsEndpoint.process(DroolsEndpoint.java
:177)
at
org.apache.servicemix.common.AsyncBaseLifeCycle.doProcess(AsyncBaseLife
Cycle.java:597)
at
org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBa
seLifeCycle.java:548)
at
org.apache.servicemix.common.AsyncBaseLifeCycle.onMessageExchange(Async
BaseLifeCycle.java:502)
... 8 more
Caused by: javax.jbi.messaging.MessagingException:
java.lang.InterruptedException
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(Delive
ryChannelImpl.java:498)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(Delive
ryChannelImpl.java:442)
at
org.apache.servicemix.common.EndpointDeliveryChannel.sendSync(EndpointD
eliveryChannel.java:102)
at
org.apache.servicemix.drools.model.JbiHelper.routeTo(JbiHelper.java:151
)
at
org.apache.servicemix.drools.model.JbiHelper.route(JbiHelper.java:109)
at
org.apache.servicemix.drools.Rule_tcphttp_http_0.consequence(Rule_tcpht
tp_http_0.java:14)
at
org.apache.servicemix.drools.Rule_tcphttp_http_0ConsequenceInvoker.eval
uate(Rule_tcphttp_http_0ConsequenceInv
oker.java:20)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:554)
... 16 more
Caused by: java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.waitForExchange
(DeliveryChannelImpl.java:699)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(Delive
ryChannelImpl.java:472)
... 23 more
So my rule.drl looks like:
package org.apache.servicemix.drools
import org.apache.servicemix.drools.model.Exchange;
global org.apache.servicemix.drools.model.JbiHelper jbi;
rule "tcphttp:http"
when
me : Exchange( status == Exchange.ACTIVE, inmsg : in != null );
eval( inmsg.xpath("/message/@type = \"http\""))
then
System.out.println("!!!!!!!!!!!!!!!!!!!!!http!!!!!!!!!!!!!!!!!!!!!!!
");
jbi.route( "service:http://knapp.com/tcphttp/dhttp_provider" );
end
rule "tcphttp:tcp"
when
me : Exchange( status == Exchange.ACTIVE, inmsg : in != null );
eval( inmsg.xpath("/message/@type = \"tcp\""));
then
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!tcp!!!!!!!!!!!!!!!!!! ");
jbi.route( "service:http://knapp.com/tcphttp/dtcp_provider" );
end
My xbean.xml for the drools su:
<beans xmlns:drools="http://servicemix.apache.org/drools/1.0"
xmlns:tcphttp="http://knapp.com/tcphttp"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://servicemix.apache.org/drools/1.0
http://servicemix.apache.org/schema/servicemix-drools-3.2.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<drools:endpoint service="tcphttp:myRouter"
endpoint="myRouter"
ruleBaseResource="classpath:rule.drl"
namespaceContext="#nsContext" />
<drools:namespace-context id="nsContext">
<drools:namespaces>
<drools:namespace
prefix="tcphttp">http://knapp.com/tcphttp</drools:namespace>
</drools:namespaces>
</drools:namespace-context>
</beans>