|
1 | 1 | # type: ignore
|
| 2 | +import os |
2 | 3 | import sys
|
3 | 4 | from traceback import print_exception
|
4 | 5 |
|
5 | 6 | from rabbitmq_amqp_python_client import (
|
6 | 7 | AddressHelper,
|
7 | 8 | AMQPMessagingHandler,
|
8 | 9 | Connection,
|
| 10 | + Converter, |
9 | 11 | CurrentUserStore,
|
10 | 12 | Environment,
|
11 | 13 | Event,
|
@@ -34,7 +36,7 @@ def __init__(self):
|
34 | 36 | self._count = 0
|
35 | 37 |
|
36 | 38 | def on_message(self, event: Event):
|
37 |
| - print("received message: " + str(event.message.body)) |
| 39 | + print("received message: " + Converter.bytes_to_string(event.message.body)) |
38 | 40 |
|
39 | 41 | # accepting
|
40 | 42 | self.delivery_context.accept(event)
|
@@ -79,15 +81,14 @@ def create_connection(environment: Environment) -> Connection:
|
79 | 81 |
|
80 | 82 |
|
81 | 83 | def main() -> None:
|
82 |
| - |
83 |
| - exchange_name = "test-exchange" |
84 |
| - queue_name = "example-queue" |
85 |
| - routing_key = "routing-key" |
| 84 | + exchange_name = "tls-test-exchange" |
| 85 | + queue_name = "tls-example-queue" |
| 86 | + routing_key = "tls-routing-key" |
86 | 87 | ca_p12_store = ".ci/certs/ca.p12"
|
87 | 88 | ca_cert_file = ".ci/certs/ca_certificate.pem"
|
88 |
| - client_cert = ".ci/certs/client_certificate.pem" |
89 |
| - client_key = ".ci/certs/client_key.pem" |
90 |
| - client_p12_store = ".ci/certs/client.p12" |
| 89 | + client_cert = ".ci/certs/client_localhost_certificate.pem" |
| 90 | + client_key = ".ci/certs/client_localhost_key.pem" |
| 91 | + client_p12_store = ".ci/certs/client_localhost.p12" |
91 | 92 | uri = "amqps://guest:guest@localhost:5671/"
|
92 | 93 |
|
93 | 94 | if sys.platform == "win32":
|
@@ -138,6 +139,9 @@ def main() -> None:
|
138 | 139 | "connection failed. working directory should be project root"
|
139 | 140 | )
|
140 | 141 | else:
|
| 142 | + print(" ca_cert_file exists: {}".format(os.path.isfile(ca_cert_file))) |
| 143 | + print(" client_cert exists: {}".format(os.path.isfile(client_cert))) |
| 144 | + print(" client_key exists: {}".format(os.path.isfile(client_key))) |
141 | 145 | environment = Environment(
|
142 | 146 | uri,
|
143 | 147 | ssl_context=PosixSslConfigurationContext(
|
@@ -187,7 +191,7 @@ def main() -> None:
|
187 | 191 |
|
188 | 192 | # publish 10 messages
|
189 | 193 | for i in range(messages_to_publish):
|
190 |
| - status = publisher.publish(Message(body="test")) |
| 194 | + status = publisher.publish(Message(body=Converter.string_to_bytes("test"))) |
191 | 195 | if status.ACCEPTED:
|
192 | 196 | print("message accepted")
|
193 | 197 | elif status.RELEASED:
|
|
0 commit comments