You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jeff V <Je...@Ultra-UEMS.com> on 2008/11/11 02:28:39 UTC

Can mina::tcp do asyncronous bidirectional messages?

The service I am connecting to is a TCP server mode socket that simultaneusly
supports two modes of communication: 

1) Request / Response 
AMQ: <Request><ParameterQuery param="temperature" /></Request> 
DEV:  <Response><QueryResult param="temperature" value="22.5"/></Response> 

AND

2) unsolicited events 
DEV:  <Event><ParameterAlarm param="temperature" value="30.1" desc="high
temperature"/></Event> 

In my slightly contrived example, AMQ is the ActiveMQ generating out bound
requests and DEV represents a device connected to the TCP port responding to
requests and also is generating event messages. 

I would like two way async communications such that my update messages can
flow into AMQ and be routed to topic subscribers, logs, persistent storage,
email etc.. 

I do not need the request response to a camel exchange, I will handle that
at a higher level.

Can I do this with the camel-mina component? If so, how?

If not, what would the best way to proceed be? 
Perhaps, a bean that is subscribing to messages for outbound and a TCP
listener thread for inbound?

Any help is much appreciated!!
-- 
View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20431804.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Claus Ibsen <cl...@gmail.com>.
This is for both came and mina reasons.

The scenario is to support request-reponse and "fire-and-forget"
exchanges (InOut and InOnly)

Camel as TCP Server (MinaProducer)
InOut is used if you as a TCP server want to be able to send a
response back to the client
InOnly is used if you as a TCP server does not send a response back.
This can be used for eg. a TCP logging server or the likes.

Camel as a TCP client (MinaConsumer)
InOut is for sending to a remote TCP server and wait for a response
InOnly is for sending to a remote TCP server and *not* wait for a response


So the sync=true|false and thus the ExchangePattern InOut or InOnly
instructs Camel and Mina how to operate.





On Tue, Nov 11, 2008 at 4:09 PM, Jeff V <Je...@ultra-uems.com> wrote:
>
> Do you know if the limitation is in Mina or the Camel-Mina component?
>
> It in the mina component sync determines the exchange pattern:
>
>        // set sync or async mode after endpoint is created
>        if (sync) {
>            endpoint.setExchangePattern(ExchangePattern.InOut);
>        } else {
>            endpoint.setExchangePattern(ExchangePattern.InOnly);
>        }
>
> From:
> http://svn.apache.org/viewvc/activemq/camel/tags/camel-1.5.0/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?view=markup
> http://svn.apache.org/viewvc/activemq/camel/tags/camel-1.5.0/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?view=markup
>
> Is this because it has to for proper mina operatio or camel component
> reasons?
> --
> View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20441499.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/

Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Jeff V <Je...@Ultra-UEMS.com>.
Do you know if the limitation is in Mina or the Camel-Mina component?

It in the mina component sync determines the exchange pattern:

        // set sync or async mode after endpoint is created
        if (sync) {
            endpoint.setExchangePattern(ExchangePattern.InOut);
        } else {
            endpoint.setExchangePattern(ExchangePattern.InOnly);
        }

From: 
http://svn.apache.org/viewvc/activemq/camel/tags/camel-1.5.0/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?view=markup
http://svn.apache.org/viewvc/activemq/camel/tags/camel-1.5.0/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?view=markup 

Is this because it has to for proper mina operatio or camel component
reasons?
-- 
View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20441499.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Giving this a 2nd thought on the way home. I guess I would like to
think about this some more.

Most components either support InOut or InOnly and not both (eg
WebServiice = InOut, Http = InOut, JMS = InOnly)
So I think it would be confusing if you can alter this behavior at
runtime based on the content of the data received or being sent.

So I guess it's best practice to expose 2 TCP listeners:
- one for InOut
- and another for InOnly


On Tue, Nov 11, 2008 at 3:55 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> Yeah and that probably sucks for you. I am wondering if we could do
> some content based (at runtime) what the message exchange pattern
> should be to support your use-case.
>
> So being able to override and set the InOnly or InOut. Could you
> create a ticket in JIRA for this request and then we could work on a
> patch to get this feature in there if you need it badly ;)
>
>
> /Claus
>
> On Tue, Nov 11, 2008 at 3:44 PM, Jeff V <Je...@ultra-uems.com> wrote:
>>
>> Then, my client would need to connect to two different ports?
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> Hi
>>>
>>> Yeah the sync=true|false is an endpoint configuration. It's not per.
>>> request based.
>>> So you might need to expose two endpoints:
>>> - one with sync=true
>>> - and one with sync=false
>>> if that is what you need.
>>>
>>>
>>> On Tue, Nov 11, 2008 at 3:23 PM, Jeff V <Je...@ultra-uems.com>
>>> wrote:
>>>>
>>>> My case is not what you are describing.
>>>>
>>>>  My client will send a message to which there is no response or request.
>>>> Messages to the client will no always get a response either.
>>>>
>>>> Correct me if I'm wrong, please, but from what I have found through the
>>>> docs
>>>> and some experimenting:
>>>>
>>>> If I set async=true I cannot send messages out, it becomes
>>>> exchangePattern=InOnly. Or, at least I am not seeing any messages coming
>>>> out
>>>> of the TCP socket.
>>>>
>>>> If I set async=false, then it is not asynchronous. My incoming <Event/>
>>>> messages would block for a response that will never come.
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20440549.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> /Claus Ibsen
>>> Apache Camel Committer
>>> Blog: http://davsclaus.blogspot.com/
>>>
>>>
>>
>> --
>> View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20440992.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
>
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/

Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Jeff V <Je...@Ultra-UEMS.com>.
I created a JIRA for this: CAMEL-1075


Claus Ibsen-2 wrote:
> 
> Hi
> 
> Yeah and that probably sucks for you. I am wondering if we could do
> some content based (at runtime) what the message exchange pattern
> should be to support your use-case.
> 
> So being able to override and set the InOnly or InOut. Could you
> create a ticket in JIRA for this request and then we could work on a
> patch to get this feature in there if you need it badly ;)
> 
> 
> /Claus
> 
> 

-- 
View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20442828.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah and that probably sucks for you. I am wondering if we could do
some content based (at runtime) what the message exchange pattern
should be to support your use-case.

So being able to override and set the InOnly or InOut. Could you
create a ticket in JIRA for this request and then we could work on a
patch to get this feature in there if you need it badly ;)


/Claus

On Tue, Nov 11, 2008 at 3:44 PM, Jeff V <Je...@ultra-uems.com> wrote:
>
> Then, my client would need to connect to two different ports?
>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> Yeah the sync=true|false is an endpoint configuration. It's not per.
>> request based.
>> So you might need to expose two endpoints:
>> - one with sync=true
>> - and one with sync=false
>> if that is what you need.
>>
>>
>> On Tue, Nov 11, 2008 at 3:23 PM, Jeff V <Je...@ultra-uems.com>
>> wrote:
>>>
>>> My case is not what you are describing.
>>>
>>>  My client will send a message to which there is no response or request.
>>> Messages to the client will no always get a response either.
>>>
>>> Correct me if I'm wrong, please, but from what I have found through the
>>> docs
>>> and some experimenting:
>>>
>>> If I set async=true I cannot send messages out, it becomes
>>> exchangePattern=InOnly. Or, at least I am not seeing any messages coming
>>> out
>>> of the TCP socket.
>>>
>>> If I set async=false, then it is not asynchronous. My incoming <Event/>
>>> messages would block for a response that will never come.
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20440549.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>>
>> /Claus Ibsen
>> Apache Camel Committer
>> Blog: http://davsclaus.blogspot.com/
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20440992.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/

Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Jeff V <Je...@Ultra-UEMS.com>.
Then, my client would need to connect to two different ports?


Claus Ibsen-2 wrote:
> 
> Hi
> 
> Yeah the sync=true|false is an endpoint configuration. It's not per.
> request based.
> So you might need to expose two endpoints:
> - one with sync=true
> - and one with sync=false
> if that is what you need.
> 
> 
> On Tue, Nov 11, 2008 at 3:23 PM, Jeff V <Je...@ultra-uems.com>
> wrote:
>>
>> My case is not what you are describing.
>>
>>  My client will send a message to which there is no response or request.
>> Messages to the client will no always get a response either.
>>
>> Correct me if I'm wrong, please, but from what I have found through the
>> docs
>> and some experimenting:
>>
>> If I set async=true I cannot send messages out, it becomes
>> exchangePattern=InOnly. Or, at least I am not seeing any messages coming
>> out
>> of the TCP socket.
>>
>> If I set async=false, then it is not asynchronous. My incoming <Event/>
>> messages would block for a response that will never come.
>> --
>> View this message in context:
>> http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20440549.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> 
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20440992.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah the sync=true|false is an endpoint configuration. It's not per.
request based.
So you might need to expose two endpoints:
- one with sync=true
- and one with sync=false
if that is what you need.


On Tue, Nov 11, 2008 at 3:23 PM, Jeff V <Je...@ultra-uems.com> wrote:
>
> My case is not what you are describing.
>
>  My client will send a message to which there is no response or request.
> Messages to the client will no always get a response either.
>
> Correct me if I'm wrong, please, but from what I have found through the docs
> and some experimenting:
>
> If I set async=true I cannot send messages out, it becomes
> exchangePattern=InOnly. Or, at least I am not seeing any messages coming out
> of the TCP socket.
>
> If I set async=false, then it is not asynchronous. My incoming <Event/>
> messages would block for a response that will never come.
> --
> View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20440549.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/

Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Jeff V <Je...@Ultra-UEMS.com>.
My case is not what you are describing.

 My client will send a message to which there is no response or request.
Messages to the client will no always get a response either.

Correct me if I'm wrong, please, but from what I have found through the docs
and some experimenting:

If I set async=true I cannot send messages out, it becomes
exchangePattern=InOnly. Or, at least I am not seeing any messages coming out
of the TCP socket.

If I set async=false, then it is not asynchronous. My incoming <Event/>
messages would block for a response that will never come.
-- 
View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20440549.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

So you want camel to expose an endpoint that uses TCP? And this
endpoint should be able to return a response the the client?

Well this is what Camel can do. Out of the box it supports
- textline
- Object serialization
- Camel Exchange

What you need is textline if you can use simple textline format. Data
ends with a \n
If not then you should write your own Mina codec where you can define
the data format.

For instance we have the camel-hl7 component that is a Mina codec that
defines the HL7 dataformat. You can peek in this code to see how to do
this.
http://activemq.apache.org/camel/hl7.html



On Tue, Nov 11, 2008 at 1:56 PM, Jeff V <Je...@ultra-uems.com> wrote:
>
> What I need is an endpoint in a camel context that exposes a tcp service. A
> client system (DEV in my previous example) will connect to the tcp service
> and send and receive messages in a known format.
>
> The messages coming from both the client and server are unsolicited and not
> part of an exchange.
>
> --
> View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20438983.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/

Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Jeff V <Je...@Ultra-UEMS.com>.
What I need is an endpoint in a camel context that exposes a tcp service. A
client system (DEV in my previous example) will connect to the tcp service
and send and receive messages in a known format.

The messages coming from both the client and server are unsolicited and not
part of an exchange.

-- 
View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20438983.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Can mina::tcp do asyncronous bidirectional messages?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Sorry I think I lost the picture. What is it excatly you want with camel-mina?

As I read it you are only connecting to a remote TCP server (not
exposing TCP services yourself?)
So what you need is to consume from the remote TCP server? Or am I wrong?

And what do you mean with async bidirectional messages?

/Claus



On Tue, Nov 11, 2008 at 2:28 AM, Jeff V <Je...@ultra-uems.com> wrote:
>
> The service I am connecting to is a TCP server mode socket that simultaneusly
> supports two modes of communication:
>
> 1) Request / Response
> AMQ: <Request><ParameterQuery param="temperature" /></Request>
> DEV:  <Response><QueryResult param="temperature" value="22.5"/></Response>
>
> AND
>
> 2) unsolicited events
> DEV:  <Event><ParameterAlarm param="temperature" value="30.1" desc="high
> temperature"/></Event>
>
> In my slightly contrived example, AMQ is the ActiveMQ generating out bound
> requests and DEV represents a device connected to the TCP port responding to
> requests and also is generating event messages.
>
> I would like two way async communications such that my update messages can
> flow into AMQ and be routed to topic subscribers, logs, persistent storage,
> email etc..
>
> I do not need the request response to a camel exchange, I will handle that
> at a higher level.
>
> Can I do this with the camel-mina component? If so, how?
>
> If not, what would the best way to proceed be?
> Perhaps, a bean that is subscribing to messages for outbound and a TCP
> listener thread for inbound?
>
> Any help is much appreciated!!
> --
> View this message in context: http://www.nabble.com/Can-mina%3A%3Atcp-do-asyncronous-bidirectional-messages--tp20431804s22882p20431804.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/