Create few connection

83 views
Skip to first unread message

Aleksandr Sytar

unread,
Mar 12, 2013, 9:59:18 AM3/12/13
to stom...@googlegroups.com
I want to use some Consumer and Producers in the code simultaneously. Now I have to bypass the limitation @exclusive transfer via stomp-object via defer.returnResult and callbacks:

class FOO(object):
   def connect():
        return Stomp.connect()

   def send(self, stomp):
        stomp.send()
        defer.returnValue(stomp)

   def recieve(self, stomp):
       stomp.subscribe()
       defer.returnValue(stomp)

df = FOO().connect()
df.addCallback(FOO().send)
df.addCallback(FOO().recieve)

As the right to do it?

nikipore

unread,
Mar 12, 2013, 11:17:53 AM3/12/13
to stom...@googlegroups.com
You can open as many subscriptions per STOMP session as you like, and you would never want to send two CONNECT frames over the same wire-level connection, which is why there is an @exclusive wrapper around the connect() method. If you want to run more than one STOMP session, then you'll have to instantiate a dedicated async.Stomp connection for each STOMP session.

I strongly recommend the @inlineCallbacks style which lets you write code in a pseudo-synchronous style. I think that a good start is the transformer example (which does receive and send frames):

    @defer.inlineCallbacks
   
def run(self):
        client
= yield Stomp(self.config).connect()
        headers
= {
           
StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL,
           
'activemq.prefetchSize': '100',
       
}
        client
.subscribe(self.IN_QUEUE, headers, listener=SubscriptionListener(self.addOne, errorDestination=self.ERROR_QUEUE))

   
def addOne(self, client, frame):
        data
= json.loads(frame.body)
        data
['count'] += 1
        client
.send(self.OUT_QUEUE, json.dumps(data))


Aleksandr Sytar

unread,
Mar 12, 2013, 1:13:01 PM3/12/13
to stom...@googlegroups.com
Thanks for you answer.
Reply all
Reply to author
Forward
0 new messages