-
15. Re: Routing with Rules
marklittle Jun 4, 2007 4:25 PM (in response to andre1001)"system.out" wrote:
I am trying to build something similar to fun-cbr but using objects in messaeg that needs to be evaluated by jboss rules.
Correct me if I am wrong: I assume when you use gateways as a bridge between esb-unaware user and esb-engine, gateway creates byteArray out of object and put it in the message body. Is that correct?
OK, if you're using gateways then you're right, although that's just how the out-of-the-box gateways are implemented, i.e., you could obviously implement your own gateways to bridge in any way you want. However, assuming you don't want to go down that route, then all you need to do is make sure you define a contract between sender and receiver about what will be within the byte array. If you do that, either explicitly within the scope of your runtime, or implicitly through some out-of-band approach (e.g., you just tell people what will be there), then you can put whatever you want in there. You could stream many different Java objects if you wanted to rely on Java serialization (obviously that places certain assumptions on the type of receiver).
If yes, then how can I put my object in esb message differently, as you suggested?We're always looking for contributors.
I would be more than happy to contribute, when I have the solution :)
Well keep us in mind ;-) -
16. Re: Routing with Rules
claudio_br Jun 4, 2007 5:28 PM (in response to andre1001)Hi system.out,
Maybe I can help you.
In request message, you can use
requestMessage = mfactory.getMessage(MessageType.JBOSS_XML);
// Object specify the command (command "gravar")
Comando cmd = new Comando();
cmd.setValor("gravar");
requestMessage.getBody().add("Comando",cmd);
// Data to process
EnderecoBean e = new EnderecoBean();
e.setId(1);
e.setName("Test");
requestMessage.getBody().add("empresa",e);
Send the message
In ESB, edit jboss-esb.xml:<service category="Empresa" name="Endereco" description="Manipula as acoes com enderecos"> <listeners> <jms-listener name="JMS-ESBListener" busidref="enderecoEsbChannel" maxThreads="1" /> </listeners> <actions> <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="ContentBasedRouter"> <property name="ruleSet" value="RegrasParaEndereco.drl" /> <property name="ruleReload" value="true" /> <property name="destinations"> <route-to destination-name="gravaEndereco" service-category="Endereco" service-name="GravaEndereco" /> <route-to destination-name="apagaEndereco" service-category="Endereco" service-name="ApagaEndereco" /> </property> <property name="object-paths"> <object-path path="body.Comando" /> </property> </action> </actions> </service>
The body.Comando must be equal a the name in request message [requestMessage.getBody().add("Comando",cmd)]
The file RegrasParaEndereco.drlpackage com import org.jboss.soa.esb.message.Message; import org.jboss.soa.esb.message.format.MessageType; import com.Comando; #declare any global variables here global java.util.List destinations; rule "Gravar" when Comando(valor == "gravar") then System.out.println("Roteador Gravar"); destinations.add("gravaEndereco"); end rule "Apagar" when Comando(valor == "apagar") then System.out.println("Roteador Apagar"); destinations.add("apagaEndereco"); end
In this code, the message is routing to service GravaEndereco or ApagaEndereco based in attribute valor of bean Comando -
17. Re: Routing with Rules
burrsutter Jun 4, 2007 11:09 PM (in response to andre1001)Claudio this is excellent.
If system.out can verify that it solves his question then it would be great if you could build a wiki page that describes this begin to end example.
We should have a quickstart that illustrates this more clearly in the future.as well in the future.
Burr -
18. Re: Routing with Rules
marklittle Jun 5, 2007 5:27 AM (in response to andre1001)"burrsutter" wrote:
Claudio this is excellent.
If system.out can verify that it solves his question then it would be great if you could build a wiki page that describes this begin to end example.
We should have a quickstart that illustrates this more clearly in the future.as well in the future.
Burr
Now unless we're really talking at cross purposes, System.out already stated that the scenario uses Gateways, which only work on the byte array part of the message. However, I'm probably as confused as you because the reference to the fun_cbr andusing objects in messaeg that needs to be evaluated by jboss rules.
doesn't require gateways at all (and hence my original response about using named objects to start with).
System.out: if none of what's been said helps you, please start up a separate forum posting specifically around your scenario. -
19. Re: Routing with Rules
system.out Jun 5, 2007 9:10 AM (in response to andre1001)Mark is right. I want to do this through gateways. It is a very simple use case:
- QueueSender sends an Object to a queue
- Gateway translate/delegate the message to esb service listener
- ContentBasedRouter re-route the message based on myObject contentpublic void sendAMessage(Object myObject /**String msg**/) throws JMSException { QueueSender send = session.createSender(que); ObjectMessage tm = session.createObjectMessage(myObject /**msg*//); send.send(tm); send.close(); }
Now, based on myObject attribute I want to re-route the message using ContentBasedRouter, just like "fun_cbr" example.
claudio_br suggestion is based on esb message, that is out of scope for the queueSender.
So far based on Mark & Burr suggestions I have 2 options:
1. build a custom gateway to put myObject in objectPath of esb message body (i.e similar to claudio code- but embeded in custom gateway)
2. build an action to 'Build & Hang' myObject from byteArray and put it in objectPath to be accessed later
another option that I am thinking is to build a service to do 'Burr''s suggestion in step 2. -
20. Re: Routing with Rules
marklittle Jun 5, 2007 11:54 AM (in response to andre1001)At what point does your scenario become something to do with the ESB? I'm just wondering if all you need is CBR in a non-ESB environment?
-
21. Re: Routing with Rules
system.out Jun 5, 2007 12:02 PM (in response to andre1001)I have many actions in the esb service pipeline. I also need to do CBR in esb environment based on "myObject".
-
22. Re: Routing with Rules
burrsutter Jun 5, 2007 2:46 PM (in response to andre1001)I would personally take option 2. It is very easy and Claudio's response is very close to that solution.
A custom gateway is harder to build.
I'm working an example for option 2 now as this is an area that I think many folks will have questions in. -
23. Re: Routing with Rules
claudio_br Jun 6, 2007 12:31 PM (in response to andre1001)Hi system.out,
You will need create java object to send in ESB.
You can do this with a webservice or with xml. In xml, you can parser xml in pojo. -
24. Re: Routing with Rules
system.out Jun 6, 2007 12:49 PM (in response to andre1001)Claudio_br,
I am sending java object to esb pipeline thrugh JCA. JCA module receives date from outside world using different protocol, parses & creates java object, then posts it to a queue to be consumed by esb actions.
Why should I create a webservice to do that? Can't esb provide a simple api to handle java objects, a gateway looking at such a Queue ?!
Burr said it is harder to build a custom gateway, and I agree. I think it is a good idea to ship jbossesb with such a gateway !
If I get time, I will build one and submit it to jbossesb team. Burr, let me know if that helps.
Thanks,
Mike -
25. Re: Routing with Rules
burrsutter Jun 6, 2007 12:57 PM (in response to andre1001)I've not tried pushing a Java object into a JMS queue and then having a ESB JMS gateway listening on that queue. That is something I'll have to try. However, if you call the ESB with its native API then passing a Java object should be no problem.
The best example of using the native API for the ESB is demonstrated by quickstart webservice_war1 where WS receives the generic SOAP request, passes it to the ESB, waits a response from the ESB and then makes the ESB response the SOAP response - HelloWorldWS.javaMessageDeliveryAdapter deliveryAdapter; Message requestMessage; Message replyMessage = null; // Create the delivery adapter for the target service (you'd normally cache this!!)... deliveryAdapter = new MessageDeliveryAdapter("MyServiceCategory", "MyService"); // Create and populate the request message... requestMessage = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML); requestMessage.getBody().setByteArray(toWhom.getBytes()); // inject the value from the WS client // Deliver the request message synchronously - timeout after 20 seconds... replyMessage = deliveryAdapter.deliverSync(requestMessage, 20000);
Instead of using requestMessage.getBody().setByteArray() or setContents(), you might use requestMessage.getBody().add("MyObject",myObject).
We also have a generic JCA gateway under development. I don't believe it will ship with the 4.2 GA version but I could be wrong.
Burr