99 OffsetSpecification ,
1010 StreamOptions ,
1111 StreamSpecification ,
12+ Environment ,
1213)
1314
1415MESSAGES_TO_PUBLISH = 100
@@ -65,8 +66,19 @@ def on_link_closed(self, event: Event) -> None:
6566 print ("link closed" )
6667
6768
68- def create_connection () -> Connection :
69- connection = Connection ("amqp://guest:guest@localhost:5672/" )
69+ def create_connection (environment : Environment ) -> Connection :
70+ connection = environment .connection ("amqp://guest:guest@localhost:5672/" )
71+ # in case of SSL enablement
72+ # ca_cert_file = ".ci/certs/ca_certificate.pem"
73+ # client_cert = ".ci/certs/client_certificate.pem"
74+ # client_key = ".ci/certs/client_key.pem"
75+ # connection = Connection(
76+ # "amqps://guest:guest@localhost:5671/",
77+ # ssl_context=SslConfigurationContext(
78+ # ca_cert=ca_cert_file,
79+ # client_cert=ClientCert(client_cert=client_cert, client_key=client_key),
80+ # ),
81+ # )
7082 connection .dial ()
7183
7284 return connection
@@ -76,15 +88,16 @@ def main() -> None:
7688 queue_name = "example-queue"
7789
7890 print ("connection to amqp server" )
79- connection = create_connection ()
91+ environment = Environment ()
92+ connection = create_connection (environment )
8093
8194 management = connection .management ()
8295
8396 management .declare_queue (StreamSpecification (name = queue_name ))
8497
8598 addr_queue = AddressHelper .queue_address (queue_name )
8699
87- consumer_connection = create_connection ()
100+ consumer_connection = create_connection (environment )
88101
89102 stream_filter_options = StreamOptions ()
90103 # can be first, last, next or an offset long
@@ -135,7 +148,7 @@ def main() -> None:
135148 print ("closing connections" )
136149 management .close ()
137150 print ("after management closing" )
138- connection .close ()
151+ environment .close ()
139152 print ("after connection closing" )
140153
141154
0 commit comments