Skip to content

Commit e49cd9c

Browse files
author
DanielePalaia
committed
moving examples and making close() method of connection public again
1 parent ec7b46d commit e49cd9c

File tree

9 files changed

+17
-11
lines changed

9 files changed

+17
-11
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ The client is distributed via [`PIP`](https://pypi.org/project/rabbitmq-amqp-pyt
3232

3333
## Getting Started
3434

35-
An example is provided [`here`](./examples/getting_started/basic_example.py) you can run it after starting a RabbitMQ 4.0 broker with:
35+
An example is provided [`here`](./examples/getting_started/getting_started.py) you can run it after starting a RabbitMQ 4.0 broker with:
3636

37-
poetry run python ./examples/getting_started/main.py
37+
poetry run python ./examples/getting_started/getting_started.py
3838

3939
### Creating a connection
4040

@@ -132,21 +132,21 @@ You can consume from a given offset or specify a default starting point (FIRST,
132132

133133
Streams filtering is also supported: https://www.rabbitmq.com/blog/2023/10/16/stream-filtering
134134

135-
You can check the [`stream example`](./examples/getting_started/example_with_streams.py) to see how to work with RabbitMQ streams.
135+
You can check the [`stream example`](./examples/streams/example_with_streams.py) to see how to work with RabbitMQ streams.
136136

137137
### SSL connections
138138

139139
The client supports TLS/SSL connections.
140140

141-
You can check the [`ssl example`](./examples/getting_started/tls_example.py) to see how to establish a secured connection
141+
You can check the [`ssl example`](./examples/tls/tls_example.py) to see how to establish a secured connection
142142

143143

144144
### Managing disconnections
145145

146146
At this stage the client doesn't support auto-reconnect but a callback is invoked everytime a remote disconnection is detected.
147147
You can use this callback to implement your own logic and eventually attempt a reconnection.
148148

149-
You can check the [`reconnection example`](./examples/getting_started/reconnection_example.py) to see how to manage disconnections and
149+
You can check the [`reconnection example`](./examples/reconnection/reconnection_example.py) to see how to manage disconnections and
150150
eventually attempt a reconnection
151151

152152

examples/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Client examples
2+
===
3+
- [Getting started](./getting_started/getting_started.py) - Producer and Consumer example without reconnection
4+
- [Reconnection](./reconnection/reconnection_example.py) - Producer and Consumer example with reconnection
5+
- [TLS](./tls/tls_example.py) - Producer and Consumer using a TLS connection
6+
- [Streams](./streams/example_with_streams.py) - Example supporting stream capabilities
File renamed without changes.

rabbitmq_amqp_python_client/connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ def management(self) -> Management:
7777
return self._management
7878

7979
# closes the connection to the AMQP 1.0 server.
80-
# This method should be called just from Environment and not from the user
81-
def _close(self) -> None:
80+
def close(self) -> None:
8281
logger.debug("Closing connection")
8382
self._conn.close()
8483
self._connections.remove(self)

rabbitmq_amqp_python_client/environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ def connection(
3737
connection._set_environment_connection_list(self._connections)
3838
return connection
3939

40+
# closes all active connections
4041
def close(self) -> None:
4142
logger.debug("Environment: Closing all pending connections")
4243
for connection in self._connections:
43-
connection._close()
44+
connection.close()
4445

4546
def connections(self) -> list[Connection]:
4647
return self._connections

tests/test_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ def test_environment_connections_management() -> None:
5656
assert len(environment.connections()) == 3
5757

5858
# this shouldn't happen but we test it anyway
59-
connection._close()
59+
connection.close()
6060

6161
assert len(environment.connections()) == 2
6262

63-
connection2._close()
63+
connection2.close()
6464

6565
assert len(environment.connections()) == 1
6666

67-
connection3._close()
67+
connection3.close()
6868

6969
assert len(environment.connections()) == 0
7070

0 commit comments

Comments
 (0)