You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by jan <ja...@yahoo.com> on 2013/02/28 09:41:45 UTC

Best protocol & network interface binding

Hi,

I am working on a project where we have one central J2EE core application
which sends out messages to approx. 500 client computers (using JMS). These
client computers have 4 network interfaces. The basic idea is that certain
services are routed on specific network interfaces. One network interface on
those client machines is a M2M-network (mobile) which is a dedicated channel
for messaging. I currently face two problems:

1) I need to find the "least traffic generating" protocol to send messages.
We pay the mobile connection for every byte we send,  thus we need to keep
the traffic as low as possible. What do you recommend: TCP, UDP
(Websockets?)?

2) Since I have 4 network-cards and interfaces I need to bind the AMQ-client
to a specific interface. The client may only receive messages f.e. on "eth3"
or whatever. The selection of the network interface depends on a
configuration file. When the client sends back a messages, it should also be
routed on this interface. I want to avoid routing with iptables. Is there a
solution?

The project is still very flexible and I could switch the strategy very
easily as long as ActiveMQ is involved.

Thanks & Greetings
Jan




--
View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Best protocol & network interface binding

Posted by Christian Posta <ch...@gmail.com>.
For 1), take a look at MQTT. It's probably the most compact protocol and
its main claim to fame is low-bandwith/limited device pub/sub.




On Thu, Feb 28, 2013 at 1:41 AM, jan <ja...@yahoo.com> wrote:

> Hi,
>
> I am working on a project where we have one central J2EE core application
> which sends out messages to approx. 500 client computers (using JMS). These
> client computers have 4 network interfaces. The basic idea is that certain
> services are routed on specific network interfaces. One network interface
> on
> those client machines is a M2M-network (mobile) which is a dedicated
> channel
> for messaging. I currently face two problems:
>
> 1) I need to find the "least traffic generating" protocol to send messages.
> We pay the mobile connection for every byte we send,  thus we need to keep
> the traffic as low as possible. What do you recommend: TCP, UDP
> (Websockets?)?
>
> 2) Since I have 4 network-cards and interfaces I need to bind the
> AMQ-client
> to a specific interface. The client may only receive messages f.e. on
> "eth3"
> or whatever. The selection of the network interface depends on a
> configuration file. When the client sends back a messages, it should also
> be
> routed on this interface. I want to avoid routing with iptables. Is there a
> solution?
>
> The project is still very flexible and I could switch the strategy very
> easily as long as ActiveMQ is involved.
>
> Thanks & Greetings
> Jan
>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: Best protocol & network interface binding

Posted by Christian Posta <ch...@gmail.com>.
Did you try SuoNayi's suggestion? That should work...



On Wed, Mar 6, 2013 at 8:04 AM, jan <ja...@yahoo.com> wrote:

> When I open a socket in Java to send/receive data, I can do the following:
>
> // open socket
> dc = DatagramChannel.open(StandardProtocolFamily.INET6);
>
> // set options ...
>
> // bind to IP. The SocketAddress comes from the network-interface using
> // NetworkInterface.getByName(networkIntf)
> dc.bind(socketAddress);
>
> But that's the theory. I use ActiveMQ to receive JMS messages and write the
> following:
>
> ActiveMQConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory("system", "manager", "tcp://some_server:61616");
>
> From the preceding answer from SuoNayi, the following code should work:
>
> ActiveMQConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory("system", "manager",
>
> "tcp://broker-ip:broker-port/local-ip:local-port?wireFormat.maxInactivityDuration=120000
> ");
>
> where the variable "local-ip" comes from the
> NetworkInterface.getByName(networkIntf) object.
>
> However, I can't find any documentation. I will try this code tomorrow.
> Further info is really appreciated.
>
> greetings
> Jan
>
>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664435.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: Re:Re: Best protocol & network interface binding

Posted by jan <ja...@yahoo.com>.
Yes, it seems to work just fine now! Thanks for the great responses!

greetings
Jan



--
View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664778.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Re:Re: Best protocol & network interface binding

Posted by jan <ja...@yahoo.com>.
I don't want the OS to do the routing. I have different network-channels and
one network-card and physical connection is dedicated to messaging. A
specific intranet lays in that world. Other network-cards have their own
physical connection and intranets etc etc. Anyway, it seems to work locally.
I will test it in the semi-production environment on Monday. I will let you
guys know if other problems pop up.

Thanks
Jan



--
View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664512.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re:Re: Best protocol & network interface binding

Posted by SuoNayi <su...@163.com>.
Yes, this feature is discovered by digging the source code and you can not find any docs/pages to mention that currently.
Maybe someone can add a entry in the FAQ.

I had tested it last year and there are 8 network interfaces on that server, I had to specify the local address to bind to communicate with the remote broker.
The downside is obvious as Raúl said.

At 2013-03-06 23:45:02,"Raúl Kripalani" <ra...@evosent.com> wrote:
>Yes, you're right. You can force the socket to bind to a particular Network Interface. But this is done to override the primary decision the OS takes based on its routing tables.
>Furthermore, by making the application layer participate in the IP routing, you likely end up with fragile code and - to some extent - breaking the nice separation of the OSI layer model. After all, you'll have to maintain the binding network interface name and/or IP in the configuration of every client machine as they change over time. 
>
>Anyway, your choice ;) Please let us know if SuoNayi's approach works.
>
>Regards,
>Raúl. 
>
>On Mar 6, 2013, at 15:04, jan wrote:
>
>> When I open a socket in Java to send/receive data, I can do the following:
>> 
>> // open socket
>> dc = DatagramChannel.open(StandardProtocolFamily.INET6);
>> 
>> // set options ... 
>> 
>> // bind to IP. The SocketAddress comes from the network-interface using 
>> // NetworkInterface.getByName(networkIntf)
>> dc.bind(socketAddress);
>> 
>> But that's the theory. I use ActiveMQ to receive JMS messages and write the
>> following:
>> 
>> ActiveMQConnectionFactory connectionFactory = new
>> ActiveMQConnectionFactory("system", "manager", "tcp://some_server:61616");
>> 
>> From the preceding answer from SuoNayi, the following code should work:
>> 
>> ActiveMQConnectionFactory connectionFactory = new
>> ActiveMQConnectionFactory("system", "manager",
>> "tcp://broker-ip:broker-port/local-ip:local-port?wireFormat.maxInactivityDuration=120000
>> ");
>> 
>> where the variable "local-ip" comes from the 
>> NetworkInterface.getByName(networkIntf) object.
>> 
>> However, I can't find any documentation. I will try this code tomorrow.
>> Further info is really appreciated.
>> 
>> greetings
>> Jan
>> 
>> 
>> 
>> 
>> 
>> --
>> View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664435.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: Best protocol & network interface binding

Posted by Raúl Kripalani <ra...@evosent.com>.
Yes, you're right. You can force the socket to bind to a particular Network Interface. But this is done to override the primary decision the OS takes based on its routing tables.
Furthermore, by making the application layer participate in the IP routing, you likely end up with fragile code and - to some extent - breaking the nice separation of the OSI layer model. After all, you'll have to maintain the binding network interface name and/or IP in the configuration of every client machine as they change over time. 

Anyway, your choice ;) Please let us know if SuoNayi's approach works.

Regards,
Raúl. 

On Mar 6, 2013, at 15:04, jan wrote:

> When I open a socket in Java to send/receive data, I can do the following:
> 
> // open socket
> dc = DatagramChannel.open(StandardProtocolFamily.INET6);
> 
> // set options ... 
> 
> // bind to IP. The SocketAddress comes from the network-interface using 
> // NetworkInterface.getByName(networkIntf)
> dc.bind(socketAddress);
> 
> But that's the theory. I use ActiveMQ to receive JMS messages and write the
> following:
> 
> ActiveMQConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory("system", "manager", "tcp://some_server:61616");
> 
> From the preceding answer from SuoNayi, the following code should work:
> 
> ActiveMQConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory("system", "manager",
> "tcp://broker-ip:broker-port/local-ip:local-port?wireFormat.maxInactivityDuration=120000
> ");
> 
> where the variable "local-ip" comes from the 
> NetworkInterface.getByName(networkIntf) object.
> 
> However, I can't find any documentation. I will try this code tomorrow.
> Further info is really appreciated.
> 
> greetings
> Jan
> 
> 
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664435.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Best protocol & network interface binding

Posted by jan <ja...@yahoo.com>.
When I open a socket in Java to send/receive data, I can do the following:

// open socket
dc = DatagramChannel.open(StandardProtocolFamily.INET6);

// set options ... 

// bind to IP. The SocketAddress comes from the network-interface using 
// NetworkInterface.getByName(networkIntf)
dc.bind(socketAddress);

But that's the theory. I use ActiveMQ to receive JMS messages and write the
following:

ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("system", "manager", "tcp://some_server:61616");

>From the preceding answer from SuoNayi, the following code should work:

ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("system", "manager",
"tcp://broker-ip:broker-port/local-ip:local-port?wireFormat.maxInactivityDuration=120000
");

where the variable "local-ip" comes from the 
NetworkInterface.getByName(networkIntf) object.

However, I can't find any documentation. I will try this code tomorrow.
Further info is really appreciated.

greetings
Jan





--
View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664435.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Best protocol & network interface binding

Posted by Raúl Kripalani <ra...@evosent.com>.
I'm not sure the JVM can do much here, and by extension the AMQ client library.

The JVM asks the OS for a network socket to communicate with an IP, and the OS queries its routing tables to select the network adapter to route traffic through.

So in my opinion, you'll need to configure your OS routing tables to achieve your goal. 

On Unix systems you can use the route command to manipulate routing tables.

Regards,
Raúl.

On Mar 6, 2013, at 12:45, jan wrote:

> No no, it is all on the client-side. I need to bind the message-listener to
> the network-interface, not the broker! The server can bind to the IPs,
> that's not the issue. But how does the client listen dedicated to a
> network-interface?
> 
> Greetings
> Jan
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664428.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Best protocol & network interface binding

Posted by jan <ja...@yahoo.com>.
No no, it is all on the client-side. I need to bind the message-listener to
the network-interface, not the broker! The server can bind to the IPs,
that's not the issue. But how does the client listen dedicated to a
network-interface?

Greetings
Jan



--
View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664428.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Best protocol & network interface binding

Posted by Raúl Kripalani <ra...@evosent.com>.
I assume you are talking about setting up a transportConnector on the broker side.
If so, just use the IP assigned to the network adapter as the hostname in the URI.

For example, if you have 3 network adapters:

en0, with IP 192.168.1.34
en1, with IP 172.16.4.2
en2, with IP 10.65.32.1

and you want the broker to listen on adapter en2 with OpenWire over TCP, you use the following transportConnector configuration:

<transportConnector uri="tcp://10.65.32.1:<portNumber>?<options>" />

You can also use hostnames or FQDNs as far as I know.

Is this what you're after?

Regards,
Raúl.

On Mar 4, 2013, at 15:20, jan wrote:

> Can anybody help me with the network-interface binding? Is it so weird that I
> try to bind my message-listener to a certain network-interface? When true,
> how can/should I do it?
> 
> greetings
> Jan
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664350.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re:Re: Best protocol & network interface binding

Posted by SuoNayi <su...@163.com>.
AMQ transport supports binding the client to the specific local address, 
but I failed to find any pages or docs to point out how to use that.
Here is an uri example to bind the client to the specific address,
tcp://broker-ip:broker-port/local-ip:local-port?wireFormat.maxInactivityDuration=120000


At 2013-03-04 23:20:17,jan <ja...@yahoo.com> wrote:
>Can anybody help me with the network-interface binding? Is it so weird that I
>try to bind my message-listener to a certain network-interface? When true,
>how can/should I do it?
>
>greetings
>Jan
>
>
>
>--
>View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664350.html
>Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Best protocol & network interface binding

Posted by jan <ja...@yahoo.com>.
Can anybody help me with the network-interface binding? Is it so weird that I
try to bind my message-listener to a certain network-interface? When true,
how can/should I do it?

greetings
Jan



--
View this message in context: http://activemq.2283324.n4.nabble.com/Best-protocol-network-interface-binding-tp4664240p4664350.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.