1 2 Previous Next 16 Replies Latest reply on Sep 22, 2014 1:41 PM by jbertram

    Routing messages to runtime discovered hosts

    zulutime

      Hello,

       

      I have one central JBoss AS 7.2  which have to send and receive messages from and to a thousand of satellite JBoss AS 7.2. Each server contains the same queue definition. The list of satellite servers vary at runtime. The central server know every server hostname/address. How can I select the satellite server queue I want to send a message?

       

      Thanks in advance,

      ZT

        • 1. Re: Routing messages to runtime discovered hosts
          jbertram

          In my opinion it's typically best in this type of situation for the satellites to pull from the central server rather than have the central server try to push to the satellites.  Is there a particular reason you want to push?

           

          Also, how are you maintaining the list of satellites on the central server?

          • 2. Re: Routing messages to runtime discovered hosts
            zulutime

            Batch jobs may be started from any server (central or satellites) and may be interact any other server. Also it is not not wished to maintain a permanent connections between central and the thousand satellites.

             

            When the satelitte app starts and stops, it send informations to the central to maintain the list.

            • 3. Re: Routing messages to runtime discovered hosts
              jbertram

              This really doesn't sound like a HornetQ question.  It sounds more like an application design question. 

               

              Is there a HornetQ specific question I can help you with?  If I've misunderstood then please clarify.

              • 4. Re: Routing messages to runtime discovered hosts
                zulutime

                My need is a JMS bridge where :

                - the remote host is dynamic (each message sent to a different host, but same queue definition)

                - network connection are not permanent to avoid the OS to run out of port (central server may deals with many thousands of connections).

                JBoss AS cannot help me because JMS bridge are configured statically.

                So my question is can I achieve this goal using HornetQ API?

                • 5. Re: Routing messages to runtime discovered hosts
                  ataylor

                  You dont need a JMS bridge, all you need is to use a either the core HornetQ API or JMS to send the messages to the destination you want.

                  • 6. Re: Routing messages to runtime discovered hosts
                    zulutime

                    Could you point me an example. Every documentation and example i found use a JNDI queue as a destination and not the pair host+queue.

                    I can create a thousand InitialContext with PROVIDER_URL to send messages to the thousand of servers but, as far as i know, it will not use HornetQ abilities. I would have to handle myself failover and connection pooling.

                    • 7. Re: Routing messages to runtime discovered hosts
                      ataylor

                      Could you point me an example. Every documentation and example i found use a JNDI queue as a destination and not the pair host+queue.

                      actually where you look up the name makes no difference, theres no endpoiny info held, its just name of topic etc.

                      I can create a thousand InitialContext with PROVIDER_URL to send messages to the thousand of servers but, as far as i know, it will not use HornetQ abilities. I would have to handle myself failover and connection pooling.

                      to use connection pooling you would have to deploy a pooled connection factor for each satellite.

                       

                      Actually i think a better approach would be to consumer from the central server rather than send from it. then you could easily use pooling on each satellite.

                      • 8. Re: Routing messages to runtime discovered hosts
                        zulutime

                        to use connection pooling you would have to deploy a pooled connection factor for each satellite.

                         

                        Actually i think a better approach would be to consumer from the central server rather than send from it. then you could easily use pooling on each satellite.

                        In my application, there are consumers and producers in every server (central and satellites) bind to the same queue definition. A message can be sent from satellite to satellite without central interaction.

                        That is, how to deploy/instanciate a connection pool (on every server) where every connection point to a different machine.

                         

                         

                        actually where you look up the name makes no difference, theres no endpoiny info held, its just name of topic etc.

                         

                        So how do i specify the host containg the target queue when i send a message?

                        • 9. Re: Routing messages to runtime discovered hosts
                          ataylor

                          In my application, there are consumers and producers in every server (central and satellites) bind to the same queue definition. A message can be sent from satellite to satellite without central interaction.

                          That is, how to deploy/instanciate a connection pool (on every server) where every connection point to a different machine.

                          you would need to configure a pooled connection factory for every satellite you want to connect to. You can do this dynamically via the CLI but that seems a bit hacky.

                           

                          So how do i specify the host containg the target queue when i send a message?

                          Its the connection factory that decides where a connection is created to.

                           

                          I think maybe using JMS and.oor bridges isnt he right approach for what you want, unless you re think how your application will work.

                          • 10. Re: Routing messages to runtime discovered hosts
                            jbertram

                            BTW, if you want a bit of example code that uses the HornetQ core API to send a message just read the documentation.  There are several code snippets (e.g. here and here) that should get you going in the right direction.

                            • 11. Re: Routing messages to runtime discovered hosts
                              zulutime

                              So I understand JMS or HornetQ is not appropriate when dealing with dynamic hosts, unless application create dynamically connection factories for every target host and drop them after messages are sent, to avoid running out of resources. Did I understand right?

                              • 12. Re: Routing messages to runtime discovered hosts
                                jbertram

                                I'm not exactly sure what you mean by "appropriate," and I still don't understand what kind of behavior you're expecting.

                                 

                                The bottom line is that if you want to send a message to a host you have to create a connection to that host.  There are several ways to create such a connection in JBoss AS 7:

                                • Configure a <pooled-connection-factory> that points to the host in question.
                                • Programmatically use the HornetQ core API (example code linked in my previous comment) in your application.
                                • Programmatically use the JMS and JNDI APIs in your application.

                                 

                                How many connections and/or pooled-connection-factory elements you can sustain in your environment depends on the resources you have available.

                                • 13. Re: Routing messages to runtime discovered hosts
                                  zulutime

                                  The probleme is the machines resources (memory and network) aren't enough to maintain permanently a thousand connection factory. I can manage in my application a map of "connection factory / target host", but is it ok to create and drop thousands of connection factories per minutes? I guess it is possible theoretically, but it looks like not using the product the way it was designed to.

                                  If I create/drop connections (and factories) manually, does failover, resume, ha... capacities enabled? For example, if I send a message, I don't care if the transportation succeeds now, as long as it will be delivered as soon as possible. But how do I know when I can drop the factory to release resources? Or after a shutdown, how do I know what connection to reestablish to resume pending messages?

                                  • 14. Re: Routing messages to runtime discovered hosts
                                    jbertram

                                    The probleme is the machines resources (memory and network) aren't enough to maintain permanently a thousand connection factory.

                                    To be clear, if you are using the HornetQ core API then you won't need any JMS connection factory objects.  However, even if you did I would be surprised if you didn't have enough memory to support a thousand or more of them.  As far as I can remember the connection factory implementation objects are not large.  What are you memory constraints? 

                                     

                                    I can manage in my application a map of "connection factory / target host", but is it ok to create and drop thousands of connection factories per minutes?

                                    Technically speaking the creation of the connection factory object itself is not considered expensive.  It's the creation of the connection from the factory that's considered expensive.  It's typically a bad idea to create and destroy connections at a high volume due to the performance penalty, but if you have other more pressing constraints then there's only so much you can do.  Trade-offs like this are almost always part of the software development process.

                                     

                                    You could batch writes to particular hosts together so that you minimize the number of times you have to create/destroy the connection to that host.  You could also try maintaining the connections to the hosts you most commonly use.

                                     

                                    If I create/drop connections (and factories) manually, does failover, resume, ha... capacities enabled? For example, if I send a message, I don't care if the transportation succeeds now, as long as it will be delivered as soon as possible.

                                    Fail-over and HA functionality are only available for live-backup pairs.  I was under the impression that you just had single hosts everywhere.  In any event, how often you create a connection has no bearing on HA.  You just need to ensure that you specify both the live and the backup in your list of initial connectors.

                                     

                                    If you send a persistent (i.e. durable) message then the send operation will not return until the server has told the client it has successfully received and persisted the message to disk.  If you send a non-persistent (i.e. non-durable) message then the send operation returns immediately under the assumption that the message is considered disposable.  This behavior can be changed via the block-on-durable-send and block-on-non-durable-send configuration parameters.  See the documentation for more info on these.  To be clear, only persistent message would survive a failure in an HA configuration.

                                     

                                    But how do I know when I can drop the factory to release resources?

                                    It depends on what kind of message you're sending.  See my answer above.

                                     

                                    Or after a shutdown, how do I know what connection to reestablish to resume pending messages?

                                    I'm not clear on your question here.  What do you mean by "resume pending messages"?

                                    1 2 Previous Next