You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Christian Schneider <ch...@die-schneider.net> on 2008/06/11 08:16:51 UTC

Putting several services on the same queue

Hi,

I am building webservice adapters for a legacy system. The system can be 
accessed with a java api but is not multi threaded. So my problem is
that I want to offer several services in one process and still make sure 
only one service is called at a time. To make this scalable I will then 
run this processes several
times on the same and different machines.

So my question is:
Can I offer several services with cxf on the same jms queue in one 
process and make sure the whole process works only on one request at a 
time and routes the reuqest to the right service?

I also would like to make management of this system as easy as possible. 
Ideally I would like this process to be a kind of application server 
where I can install and deinstall services while it is running.
Still they should listen on one queue and work single threaded. I 
imagined doing this with an osgi server. The problem is that probably 
then each bundle will have it´s own cxf and they are not single threaded 
anymore.

Any ideas for this?

Best regards

Christian

Re: Putting several services on the same queue

Posted by Daniel Kulp <dk...@apache.org>.
On Jun 14, 2008, at 3:58 AM, Christian Schneider wrote:

> Hi Daniel,
>
> I have got an idea how I could implement several services on one  
> queue without too much problems.
>
> The idea is to publish the services with a local endpoint only. Then  
> I configure one additional endpoint on jms and write a custom  
> invoker. The invoker figures out what local endpoint the request  
> should go to and invokes it. Then it forwards the reply back to jms.  
> It could find the correct endpoint either by analysing the namespace  
> of the xml or by using ws addressing. The only thing is I do not  
> know exactly how to implement this.
>
> Is it better to do this in cxf directly or should I rather use camel  
> for this? The jms and invoker part sounds to me like it could be  
> done in camel quite nicely but I am not sure. Especially I do not  
> know how to do synchronous things in camel.

It definitely could be done in camel.   By default, the listener on a  
JMS queue is single threaded.   Thus, all requests would come in on  
one thread.      No syncronization would be needed.   You would just  
take the message, figure out where to dispatch it to, and dispatch  
it.   It would be completely single threaded by default.


Digging into the code a bit, I notice our JMS transport does:
WorkQueueManager wqm = base.bus.getExtension(WorkQueueManager.class);
if (null != wqm) {
         executor = wqm.getAutomaticWorkQueue();
}

Thus, if you put a single threaded workqueue thing on the bus, that  
would accomplish it as well.   The API's look like they have some  
support for this already, but they aren't hooked up to anything.  :-(

The simplest thing would probably be to write you own subclass/ 
implementation of WorkQueueManager  (fairly simple) and configure that  
in to the bus.


Dan




>
>
> Best regards
>
> Christian
>
>
> Daniel Kulp schrieb:
>>
>> On Jun 11, 2008, at 2:16 AM, Christian Schneider wrote:
>>
>>> Hi,
>>>
>>> I am building webservice adapters for a legacy system. The system  
>>> can be accessed with a java api but is not multi threaded. So my  
>>> problem is
>>> that I want to offer several services in one process and still  
>>> make sure only one service is called at a time. To make this  
>>> scalable I will then run this processes several
>>> times on the same and different machines.
>>>
>>> So my question is:
>>> Can I offer several services with cxf on the same jms queue in one  
>>> process
>>
>> I think so, yes.   With configuration, you can use message  
>> selectors to put multiple endpoints on the same queue and have the  
>> messages dispatched correctly.
>>
>>
>>> and make sure the whole process works only on one request at a  
>>> time and routes the reuqest to the right service?
>>>
>>
>> This one I'm not sure about.   Good question.   CXF is definitely  
>> designed for high scalability and mutlti-threaded cases.
>>
>> Hmmmm....    One option, I guess, would be to write a custom  
>> invoker that syncronizes things and use a single instance of that  
>> invoker for all the endpoints.   Might be harder for dynamic  
>> deployments though.
>>
>> Another option might be to write a pair of interceptors, one for  
>> the IN chain and one for the out/out fault chains that just aquire/ 
>> release a lock of some sort.
>>
>> Dan
>>
>>
>>
>>> I also would like to make management of this system as easy as  
>>> possible. Ideally I would like this process to be a kind of  
>>> application server where I can install and deinstall services  
>>> while it is running.
>>> Still they should listen on one queue and work single threaded. I  
>>> imagined doing this with an osgi server. The problem is that  
>>> probably then each bundle will have it´s own cxf and they are not  
>>> single threaded anymore.
>>>
>>> Any ideas for this?
>>>
>>> Best regards
>>>
>>> Christian
>>
>> ---
>> Daniel Kulp
>> dkulp@apache.org
>> http://www.dankulp.com/blog
>>
>>
>>
>>
>>
>

---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog





Re: Putting several services on the same queue

Posted by Christian Schneider <ch...@die-schneider.net>.
Hi Daniel,

I have got an idea how I could implement several services on one queue 
without too much problems.

The idea is to publish the services with a local endpoint only. Then I 
configure one additional endpoint on jms and write a custom invoker. The 
invoker figures out what local endpoint the request should go to and 
invokes it. Then it forwards the reply back to jms. It could find the 
correct endpoint either by analysing the namespace of the xml or by 
using ws addressing. The only thing is I do not know exactly how to 
implement this.

Is it better to do this in cxf directly or should I rather use camel for 
this? The jms and invoker part sounds to me like it could be done in 
camel quite nicely but I am not sure. Especially I do not know how to do 
synchronous things in camel.

Best regards

Christian


Daniel Kulp schrieb:
>
> On Jun 11, 2008, at 2:16 AM, Christian Schneider wrote:
>
>> Hi,
>>
>> I am building webservice adapters for a legacy system. The system can 
>> be accessed with a java api but is not multi threaded. So my problem is
>> that I want to offer several services in one process and still make 
>> sure only one service is called at a time. To make this scalable I 
>> will then run this processes several
>> times on the same and different machines.
>>
>> So my question is:
>> Can I offer several services with cxf on the same jms queue in one 
>> process
>
> I think so, yes.   With configuration, you can use message selectors 
> to put multiple endpoints on the same queue and have the messages 
> dispatched correctly.
>
>
>> and make sure the whole process works only on one request at a time 
>> and routes the reuqest to the right service?
>>
>
> This one I'm not sure about.   Good question.   CXF is definitely 
> designed for high scalability and mutlti-threaded cases.
>
> Hmmmm....    One option, I guess, would be to write a custom invoker 
> that syncronizes things and use a single instance of that invoker for 
> all the endpoints.   Might be harder for dynamic deployments though.
>
> Another option might be to write a pair of interceptors, one for the 
> IN chain and one for the out/out fault chains that just aquire/release 
> a lock of some sort.
>
> Dan
>
>
>
>> I also would like to make management of this system as easy as 
>> possible. Ideally I would like this process to be a kind of 
>> application server where I can install and deinstall services while 
>> it is running.
>> Still they should listen on one queue and work single threaded. I 
>> imagined doing this with an osgi server. The problem is that probably 
>> then each bundle will have it´s own cxf and they are not single 
>> threaded anymore.
>>
>> Any ideas for this?
>>
>> Best regards
>>
>> Christian
>
> ---
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
>
>
>
>
>


Re: Putting several services on the same queue

Posted by Christian Schneider <ch...@die-schneider.net>.
I just thought about my soapaction idea a second time. Probably this is 
not such a good idea. If understood it right soapaction identifies the 
method in the service. So probably this is not good to distinguish the 
services. Perhaps the message selector is a good idea after all ;-) 
Though I would prefer cxf to simply take the first message and then 
route them to the respective service. if that is possible at all.

Greetings

Christian

Re: Putting several services on the same queue

Posted by Christian Schneider <ch...@die-schneider.net>.
I have just looked into the code of cxf to find out how it handles 
incoming JMS Messages. In JMSDestination a listener thread is created 
that reads from the queue and then dispatches the call to an 
AutomaticWorkQueue. The default implementation of this is not 
configurable and uses several threads. But I think if I write my own 
AutomaticWorkQueue that makes sure one message is processed at a time I 
could get nearer to what I want. What do you think?

Greetings

Christian

Christian Schneider schrieb:
> Daniel Kulp schrieb:
>>
>> On Jun 11, 2008, at 2:16 AM, Christian Schneider wrote:
>>
>>> Hi,
>>>
>>> I am building webservice adapters for a legacy system. The system 
>>> can be accessed with a java api but is not multi threaded. So my 
>>> problem is
>>> that I want to offer several services in one process and still make 
>>> sure only one service is called at a time. To make this scalable I 
>>> will then run this processes several
>>> times on the same and different machines.
>>>
>>> So my question is:
>>> Can I offer several services with cxf on the same jms queue in one 
>>> process
>>
>> I think so, yes.   With configuration, you can use message selectors 
>> to put multiple endpoints on the same queue and have the messages 
>> dispatched correctly.
> I am not sure if message selectors are what I want. If I have two 
> services on a queue and use message selectors, what will happen if I 
> have two messages in the queue one for each service? Let´s assume the 
> first message is for service 1 and the second for service2.
> What I want is that the engine listens on the queue with one thread, 
> takes one message, finds out, which service it should be routed to and 
> calls the service. When the service returns it should take the next 
> message and route it to service 2. I guess with selectors both 
> messages would be processed in parallel. Can´t I simply configure both 
> services on the same queue and cxf routes the message like I wrote 
> using the SoapAction? Or will cxf automatically start a new thread for 
> each service it hosts? Is this behaviour configurable?
>>
>>
>>> and make sure the whole process works only on one request at a time 
>>> and routes the reuqest to the right service?
>>>
>>
>> This one I'm not sure about.   Good question.   CXF is definitely 
>> designed for high scalability and mutlti-threaded cases.
>>
>> Hmmmm....    One option, I guess, would be to write a custom invoker 
>> that syncronizes things and use a single instance of that invoker for 
>> all the endpoints.   Might be harder for dynamic deployments though.
>>
>> Another option might be to write a pair of interceptors, one for the 
>> IN chain and one for the out/out fault chains that just 
>> aquire/release a lock of some sort.
> The interceptor solution sounds quite good to me. Though I would 
> prefer that cxf simply uses one thread only for both services. Then I 
> guess no interceptor and synchronizing would be necessary.
>>
>>> I also would like to make management of this system as easy as 
>>> possible. Ideally I would like this process to be a kind of 
>>> application server where I can install and deinstall services while 
>>> it is running.
>>> Still they should listen on one queue and work single threaded. I 
>>> imagined doing this with an osgi server. The problem is that 
>>> probably then each bundle will have it´s own cxf and they are not 
>>> single threaded anymore.
> Does cxf already run on osgi servers as a bundle? If I install several 
> of my own bundles and they all offer services using cxf. Will there be 
> only one instance of cxf in the osgi system then or one per bundle 
> that uses cxf? If there would be only one instance synchronizing the 
> requests would probably be quite easy. Perhaps even the one thread 
> strategy from above would work.
>
> What osgi server would you recommand for my setup. A natural guess for 
> me would be servicemix 4. But it is not finished till now.
>
> Greetings and thanks for the help
>
> Christian
> ---
> http://www.liquid-reality.de
>
>


Re: Putting several services on the same queue

Posted by Christian Schneider <ch...@die-schneider.net>.
Daniel Kulp schrieb:
>
> On Jun 11, 2008, at 2:16 AM, Christian Schneider wrote:
>
>> Hi,
>>
>> I am building webservice adapters for a legacy system. The system can 
>> be accessed with a java api but is not multi threaded. So my problem is
>> that I want to offer several services in one process and still make 
>> sure only one service is called at a time. To make this scalable I 
>> will then run this processes several
>> times on the same and different machines.
>>
>> So my question is:
>> Can I offer several services with cxf on the same jms queue in one 
>> process
>
> I think so, yes.   With configuration, you can use message selectors 
> to put multiple endpoints on the same queue and have the messages 
> dispatched correctly.
I am not sure if message selectors are what I want. If I have two 
services on a queue and use message selectors, what will happen if I 
have two messages in the queue one for each service? Let´s assume the 
first message is for service 1 and the second for service2.
What I want is that the engine listens on the queue with one thread, 
takes one message, finds out, which service it should be routed to and 
calls the service. When the service returns it should take the next 
message and route it to service 2. I guess with selectors both messages 
would be processed in parallel. Can´t I simply configure both services 
on the same queue and cxf routes the message like I wrote using the 
SoapAction? Or will cxf automatically start a new thread for each 
service it hosts? Is this behaviour configurable?
>
>
>> and make sure the whole process works only on one request at a time 
>> and routes the reuqest to the right service?
>>
>
> This one I'm not sure about.   Good question.   CXF is definitely 
> designed for high scalability and mutlti-threaded cases.
>
> Hmmmm....    One option, I guess, would be to write a custom invoker 
> that syncronizes things and use a single instance of that invoker for 
> all the endpoints.   Might be harder for dynamic deployments though.
>
> Another option might be to write a pair of interceptors, one for the 
> IN chain and one for the out/out fault chains that just aquire/release 
> a lock of some sort.
The interceptor solution sounds quite good to me. Though I would prefer 
that cxf simply uses one thread only for both services. Then I guess no 
interceptor and synchronizing would be necessary.
>
>> I also would like to make management of this system as easy as 
>> possible. Ideally I would like this process to be a kind of 
>> application server where I can install and deinstall services while 
>> it is running.
>> Still they should listen on one queue and work single threaded. I 
>> imagined doing this with an osgi server. The problem is that probably 
>> then each bundle will have it´s own cxf and they are not single 
>> threaded anymore.
Does cxf already run on osgi servers as a bundle? If I install several 
of my own bundles and they all offer services using cxf. Will there be 
only one instance of cxf in the osgi system then or one per bundle that 
uses cxf? If there would be only one instance synchronizing the requests 
would probably be quite easy. Perhaps even the one thread strategy from 
above would work.

What osgi server would you recommand for my setup. A natural guess for 
me would be servicemix 4. But it is not finished till now.

Greetings and thanks for the help

Christian
---
http://www.liquid-reality.de


Re: Putting several services on the same queue

Posted by Daniel Kulp <dk...@apache.org>.
On Jun 11, 2008, at 2:16 AM, Christian Schneider wrote:

> Hi,
>
> I am building webservice adapters for a legacy system. The system  
> can be accessed with a java api but is not multi threaded. So my  
> problem is
> that I want to offer several services in one process and still make  
> sure only one service is called at a time. To make this scalable I  
> will then run this processes several
> times on the same and different machines.
>
> So my question is:
> Can I offer several services with cxf on the same jms queue in one  
> process

I think so, yes.   With configuration, you can use message selectors  
to put multiple endpoints on the same queue and have the messages  
dispatched correctly.


> and make sure the whole process works only on one request at a time  
> and routes the reuqest to the right service?
>

This one I'm not sure about.   Good question.   CXF is definitely  
designed for high scalability and mutlti-threaded cases.

Hmmmm....    One option, I guess, would be to write a custom invoker  
that syncronizes things and use a single instance of that invoker for  
all the endpoints.   Might be harder for dynamic deployments though.

Another option might be to write a pair of interceptors, one for the  
IN chain and one for the out/out fault chains that just aquire/release  
a lock of some sort.

Dan



> I also would like to make management of this system as easy as  
> possible. Ideally I would like this process to be a kind of  
> application server where I can install and deinstall services while  
> it is running.
> Still they should listen on one queue and work single threaded. I  
> imagined doing this with an osgi server. The problem is that  
> probably then each bundle will have it´s own cxf and they are not  
> single threaded anymore.
>
> Any ideas for this?
>
> Best regards
>
> Christian

---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog