public void Remove(string endpoint, string messageName)
        {
            var toBeStored = new List <MsmqSubscriptionStorageItem>();

            foreach (var message in storageQueue.GetAllMessages())
            {
                var item = bodySerializer.Deserialize(message.BodyStream, typeof(MsmqSubscriptionStorageItem)) as MsmqSubscriptionStorageItem;
                if (item == null)
                {
                    continue;
                }

                if (item.Endpoint == endpoint && item.MessageName == messageName)
                {
                    continue;
                }
                toBeStored.Add(item);
            }

            using (var tx = new MessageQueueTransaction())
                using (var stream = new MemoryStream())
                {
                    tx.Begin();

                    storageQueue.Purge();

                    foreach (var item in toBeStored)
                    {
                        bodySerializer.Serialize(item, stream);

                        var msg = new Message
                        {
                            BodyStream = stream,
                            Label      = item.Endpoint
                        };

                        storageQueue.Send(msg, tx);
                    }

                    tx.Commit();
                }

            var remove = subscriptions.FirstOrDefault(x => x.Endpoint == endpoint && x.MessageName == messageName);

            if (remove != null)
            {
                subscriptions.Remove(remove);
            }
        }
Exemple #2
0
        public void Invoke(MiddlewareContext context, Action next)
        {
            var channelMessage  = context.ChannelMessage;
            var messageTypeName = channelMessage.GetHeader(MessageHeaders.MessageFullname);
            var handlerInfos    = handlerCache.GetHandlerInfo(messageTypeName).ToList();

            if (handlerInfos.Any())
            {
                var messageType = handlerInfos.First().MessageType;
                context.Message = bodySerializer.Deserialize(channelMessage.BodyStream, messageType);
            }
            else
            {
                context.Message = bodySerializer.Deserialize(channelMessage.BodyStream, typeof(object));
            }

            next();
        }