Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Store channel instead of exchange in received message #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/amqp/channel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ class AMQP::Channel
when Protocol::Basic::Deliver
msg.delivery_tag = content_method.delivery_tag
msg.redelivered = content_method.redelivered
msg.exchange = @exchanges[content_method.exchange]
msg.channel = self
msg.key = content_method.routing_key
subscriber = @subscribers[content_method.consumer_tag]?
unless subscriber
Expand All @@ -595,7 +595,7 @@ class AMQP::Channel
when Protocol::Basic::GetOk
msg.delivery_tag = content_method.delivery_tag
msg.redelivered = content_method.redelivered
msg.exchange = @exchanges[content_method.exchange]
msg.channel = self
msg.key = content_method.routing_key
msg.message_count = content_method.message_count
@msg.send(msg)
Expand Down
17 changes: 9 additions & 8 deletions src/amqp/message.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "./exchange"
# require "./exchange"
require "./channel"

class AMQP::Message

Expand All @@ -12,7 +13,7 @@ class AMQP::Message
property delivery_tag : UInt64?
property redelivered : Bool?
# these two properties are also provider by 'return' method
property exchange : AMQP::Exchange?
property channel : AMQP::Channel?
property key : String?

# provided by amqp 'get' method
Expand All @@ -26,25 +27,25 @@ class AMQP::Message
end

def ack
if exchange = @exchange
if channel = @channel
if tag = @delivery_tag
exchange.channel.ack(tag)
channel.ack(tag)
end
end
end

def reject(requeue = false)
if exchange = @exchange
if channel = @channel
if tag = @delivery_tag
exchange.channel.reject(tag, requeue)
channel.reject(tag, requeue)
end
end
end

def nack(requeue = false)
if exchange = @exchange
if channel = @channel
if tag = @delivery_tag
exchange.channel.nack(tag, requeue: requeue)
channel.nack(tag, requeue: requeue)
end
end
end
Expand Down