Beispiel #1
0
        MessageQueue GetInputQueue()
        {
            if (_inputQueue != null)
            {
                return(_inputQueue);
            }

            lock (this)
            {
                if (_inputQueue != null)
                {
                    return(_inputQueue);
                }

                var inputQueuePath = MsmqUtil.GetPath(_inputQueueName);

                MsmqUtil.EnsureQueueExists(inputQueuePath, _log);
                MsmqUtil.EnsureMessageQueueIsTransactional(inputQueuePath);

                _inputQueue = new MessageQueue(inputQueuePath, QueueAccessMode.SendAndReceive)
                {
                    MessageReadPropertyFilter = new MessagePropertyFilter
                    {
                        Id        = true,
                        Extension = true,
                        Body      = true,
                    }
                };
            }

            return(_inputQueue);
        }
Beispiel #2
0
        public void CreateQueue(string address)
        {
            if (!MsmqUtil.IsLocal(address))
            {
                return;
            }

            var inputQueuePath = MsmqUtil.GetPath(address);

            MsmqUtil.EnsureQueueExists(inputQueuePath);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a queue with the given address, unless the address is of a remote queue - in that case,
        /// this call is ignored
        /// </summary>
        public void CreateQueue(string address)
        {
            if (!MsmqUtil.IsLocal(address))
            {
                return;
            }

            var inputQueuePath = MsmqUtil.GetPath(address);

            MsmqUtil.EnsureQueueExists(inputQueuePath, _log);
            MsmqUtil.EnsureMessageQueueIsTransactional(inputQueuePath);
        }
Beispiel #4
0
        public async Task Send(string destinationAddress, TransportMessage message, ITransactionContext context)
        {
            if (destinationAddress == null)
            {
                throw new ArgumentNullException("destinationAddress");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var logicalMessage = CreateMsmqMessage(message);

            var messageQueueTransaction = context.GetOrAdd(CurrentTransactionKey, () =>
            {
                var messageQueueTransaction1 = new MessageQueueTransaction();
                messageQueueTransaction1.Begin();

                context.OnCommitted(async() => messageQueueTransaction1.Commit());

                return(messageQueueTransaction1);
            });

            var sendQueues = context.GetOrAdd(CurrentOutgoingQueuesKey, () =>
            {
                var messageQueues = new ConcurrentDictionary <string, MessageQueue>(StringComparer.InvariantCultureIgnoreCase);

                context.OnDisposed(() =>
                {
                    foreach (var messageQueue in messageQueues.Values)
                    {
                        messageQueue.Dispose();
                    }
                });

                return(messageQueues);
            });

            var sendQueue = sendQueues.GetOrAdd(MsmqUtil.GetPath(destinationAddress), _ =>
            {
                var messageQueue = new MessageQueue(MsmqUtil.GetPath(destinationAddress), QueueAccessMode.Send);

                return(messageQueue);
            });

            sendQueue.Send(logicalMessage, messageQueueTransaction);
        }
Beispiel #5
0
        MessageQueue GetInputQueue()
        {
            if (_inputQueue != null)
            {
                return(_inputQueue);
            }

            lock (this)
            {
                if (_inputQueue != null)
                {
                    return(_inputQueue);
                }

                var inputQueuePath = MsmqUtil.GetPath(_inputQueueName);

                if (_newQueueCallbacks.Any())
                {
                    MsmqUtil.EnsureQueueExists(inputQueuePath, _log, messageQueue =>
                    {
                        _newQueueCallbacks.ForEach(callback => callback(messageQueue));
                    });
                }
                else
                {
                    MsmqUtil.EnsureQueueExists(inputQueuePath, _log);
                }
                MsmqUtil.EnsureMessageQueueIsTransactional(inputQueuePath);

                _inputQueue = new MessageQueue(inputQueuePath, QueueAccessMode.SendAndReceive)
                {
                    MessageReadPropertyFilter = new MessagePropertyFilter
                    {
                        Id        = true,
                        Extension = true,
                        Body      = true,
                    }
                };
            }

            return(_inputQueue);
        }
Beispiel #6
0
        /// <summary>
        /// Creates a queue with the given address, unless the address is of a remote queue - in that case,
        /// this call is ignored
        /// </summary>
        public void CreateQueue(string address)
        {
            if (!MsmqUtil.IsLocal(address))
            {
                return;
            }

            var inputQueuePath = MsmqUtil.GetPath(address);

            if (_newQueueCallbacks.Any())
            {
                MsmqUtil.EnsureQueueExists(inputQueuePath, _log, messageQueue =>
                {
                    _newQueueCallbacks.ForEach(callback => callback(messageQueue));
                });
            }
            else
            {
                MsmqUtil.EnsureQueueExists(inputQueuePath, _log);
            }

            MsmqUtil.EnsureMessageQueueIsTransactional(inputQueuePath);
        }