diff --git a/LICENSE b/LICENSE index a08e0765bf9ed2266701bc5fbe3f1c2a767e0a0a..21a8338bd508348297df1462eb20003df7129fc9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 DMS Serwis s.c. +Copyright (c) 2016-2017 DMS Serwis s.c. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -21,4 +21,4 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -resources/*: Copyright (c) 2016 OASIS \ No newline at end of file +resources/*: Copyright (c) 2016-2017 OASIS \ No newline at end of file diff --git a/coolamqp/connection/definition.py b/coolamqp/connection/definition.py index 58682beab89ad6aa6aeb328e9105daf4772e1b03..fe4695f2e5a49736638328cf057adf8871662407 100644 --- a/coolamqp/connection/definition.py +++ b/coolamqp/connection/definition.py @@ -26,8 +26,3 @@ class NodeDefinition(object): self.virtual_host = virtual_host self.heartbeat = heartbeat - def to_connection_object(self): - """ - Return a Connection object that - :return: - """ diff --git a/coolamqp/connection/state.py b/coolamqp/connection/state.py index b1c75e43b6352cf53123b77be386d72ec498630b..b5013cc763599647df79795e9a306ff7fc6d2a27 100644 --- a/coolamqp/connection/state.py +++ b/coolamqp/connection/state.py @@ -22,6 +22,28 @@ class Broker(object): self.free_channels = [] # list of channels usable for consuming shit + @staticmethod + def from_node_def(node_def, listener_thread, debug=True): + """ + :param node_def: NodeDefinition to use + :param listener_thread: ListenerThread to use + :return: a Broker with Connection. + """ + import socket + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((node_def.host, node_def.port)) + s.settimeout(0) + s.send('AMQP\x00\x00\x09\x01') + + from coolamqp.uplink import Connection + con = Connection(s, listener_thread) + + if debug: + from coolamqp.uplink.transcript import SessionTranscript + con.transcript = SessionTranscript() + + return Broker(con, node_def) + def connect(self): """Return an LinkSetup order to get when it connects""" diff --git a/coolamqp/uplink/handshake.py b/coolamqp/uplink/handshake.py index 48e50c191c4349ec32d03bba6138c2be72662bb6..3cba0c0d855c350e105acbcf1ea2ac2e7eaeeede 100644 --- a/coolamqp/uplink/handshake.py +++ b/coolamqp/uplink/handshake.py @@ -15,9 +15,13 @@ CLIENT_DATA = [ # because RabbitMQ is some kind of a fascist and does not allow # these fields to be of type short-string (b'product', (b'CoolAMQP', b'S')), - (b'version', (b'1.0', b'S')), - (b'copyright', (b'Copyright (C) 2016 DMS Serwis', b'S')), - (b'information', (b'Licensed under the MIT License. See https://github.com/smok-serwis/coolamqp for details', b'S')) + (b'version', (b'develop', b'S')), + (b'copyright', (b'Copyright (C) 2016-2017 DMS Serwis', b'S')), + (b'information', (b'Licensed under the MIT License.\nSee https://github.com/smok-serwis/coolamqp for details', b'S')), + (b'capabilities', ([ + (b'consumer_cancel_notify', (True, b't')), + (b'connection.blocked', (True, b't')) + ], b'F')) ] diff --git a/tests/run.py b/tests/run.py index 262ea2fbdb12ef42b0aea732ca5aa2ace0e6cd24..d74a93312c4ebf4f9ae59063e7ed589ddbaca1f5 100644 --- a/tests/run.py +++ b/tests/run.py @@ -1,36 +1,22 @@ # coding=UTF-8 from __future__ import absolute_import, division, print_function -from coolamqp.uplink import ListenerThread, Connection -import socket +from coolamqp.uplink import ListenerThread import time from coolamqp.connection.state import Broker from coolamqp.connection import NodeDefinition -from coolamqp.uplink.transcript import SessionTranscript -def newc(): - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect(('127.0.0.1', 5672)) - s.settimeout(0) - s.send('AMQP\x00\x00\x09\x01') - return s - - -from coolamqp.uplink import Handshaker NODE = NodeDefinition('127.0.0.1', 5672, 'user', 'user', heartbeat=5) - if __name__ == '__main__': lt = ListenerThread() lt.start() - con = Connection(newc(), lt) - con.transcript = SessionTranscript() - broker = Broker(con, NODE) + broker = Broker.from_node_def(NODE, lt) - broker.connect() + broker.connect().wait() time.sleep(50)