Skip to content
Browse files

drop messages when there is no subscriber instead of crashing the who…

…le channel
  • Loading branch information...
1 parent b1776d9 commit 277ebd41583043119f42dc5c7a7ab40cc7c6f9b7 @hreinhardt hreinhardt committed Apr 4, 2011
Showing with 10 additions and 6 deletions.
  1. +10 −6 Network/AMQP.hs
View
16 Network/AMQP.hs
@@ -811,12 +811,16 @@ channelReceiver chan = do
(ShortString routingKey))
properties msgBody) =
withMVar (consumers chan) (\s -> do
- let subscriber = fromJust $ M.lookup consumerTag s
- let msg = msgFromContentHeaderProperties properties msgBody
- let env = Envelope {envDeliveryTag = deliveryTag, envRedelivered = redelivered,
- envExchangeName = exchangeName, envRoutingKey = routingKey, envChannel = chan}
-
- subscriber (msg, env)
+ case M.lookup consumerTag s of
+ Just subscriber -> do
+ let msg = msgFromContentHeaderProperties properties msgBody
+ let env = Envelope {envDeliveryTag = deliveryTag, envRedelivered = redelivered,
+ envExchangeName = exchangeName, envRoutingKey = routingKey, envChannel = chan}
+
+ subscriber (msg, env)
+ Nothing ->
+ -- got a message, but have no registered subscriber; so drop it
+ return ()
)
handleAsync (SimpleMethod (Channel_close errorNum (ShortString errorMsg) _ _)) = do

0 comments on commit 277ebd4

Please sign in to comment.
Something went wrong with that request. Please try again.