Skip to content

Commit

Permalink
Support for passing Connection::Blocked frames to downstream clients
Browse files Browse the repository at this point in the history
Fixes #146
  • Loading branch information
carlhoerberg committed Mar 9, 2024
1 parent abee514 commit 24bc763
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/amqproxy/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ module AMQProxy
capabilities: {
consumer_priorities: true,
exchange_exchange_bindings: true,
"connection.blocked": false,
"connection.blocked": true,
authentication_failure_close: true,
per_consumer_qos: true,
"basic.nack": true,
Expand Down
20 changes: 19 additions & 1 deletion src/amqproxy/upstream.cr
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ module AMQProxy
end
return
when AMQ::Protocol::Frame::Connection::CloseOk then return
when AMQ::Protocol::Frame::Connection::Blocked,
AMQ::Protocol::Frame::Connection::Unblocked
send_to_all_clients(frame)
when AMQ::Protocol::Frame::Channel::OpenOk # we assume it always succeeds
when AMQ::Protocol::Frame::Channel::CloseOk # when channel pool requested channel close
else
Expand Down Expand Up @@ -125,6 +128,21 @@ module AMQProxy
end
end

private def send_to_all_clients(frame : AMQ::Protocol::Frame::Connection)
Log.debug { "Sending broadcast frame to all client connections" }
clients = Set(Client).new
@channels_lock.synchronize do
@channels.each_value do |downstream_channel|
if dc = downstream_channel
clients << dc.client
end
end
end
clients.each do |client|
client.write frame
end
end

# Forward frames from client to upstream
def write(frame : AMQ::Protocol::Frame) : Nil
case frame
Expand Down Expand Up @@ -232,7 +250,7 @@ module AMQProxy
capabilities: {
consumer_priorities: true,
exchange_exchange_bindings: true,
"connection.blocked": false,
"connection.blocked": true,
authentication_failure_close: true,
per_consumer_qos: true,
"basic.nack": true,
Expand Down

0 comments on commit 24bc763

Please sign in to comment.