Skip to content

Commit

Permalink
Merge pull request #1216 from pika/lrb-fix-exception-and-example
Browse files Browse the repository at this point in the history
Fix use of InvalidChannelNumber exception
  • Loading branch information
lukebakken committed Jun 11, 2019
2 parents a3972b9 + 9c3e2fe commit 24e6c9a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Example::
def on_connected(connection):
"""Called when we are fully connected to RabbitMQ"""
# Open a channel
connection.channel(on_channel_open)
connection.channel(on_open_callback=on_channel_open)

# Step #3
def on_channel_open(new_channel):
Expand All @@ -79,7 +79,7 @@ Example::

# Step #1: Connect to RabbitMQ using the default parameters
parameters = pika.ConnectionParameters()
connection = pika.SelectConnection(parameters, on_connected)
connection = pika.SelectConnection(parameters, on_open_callback=on_connected)

try:
# Loop so we can communicate with RabbitMQ
Expand Down
2 changes: 1 addition & 1 deletion pika/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, connection, channel_number, on_open_callback):
"""
if not isinstance(channel_number, int):
raise exceptions.InvalidChannelNumber
raise exceptions.InvalidChannelNumber(channel_number)

validators.rpc_completion_callback(on_open_callback)

Expand Down
3 changes: 3 additions & 0 deletions pika/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,8 +1251,11 @@ def channel(self, channel_number=None, on_open_callback=None):
raise exceptions.ConnectionWrongStateError(
'Channel allocation requires an open connection: %s' % self)

validators.rpc_completion_callback(on_open_callback)

if not channel_number:
channel_number = self._next_channel_number()

self._channels[channel_number] = self._create_channel(
channel_number, on_open_callback)
self._add_channel_callbacks(channel_number)
Expand Down

0 comments on commit 24e6c9a

Please sign in to comment.