void MsmqOnPeekComplete(IAsyncResult result)
        {
            // Complete the MSMQ peek operation. If a timeout occured, peek again.
            System.Messaging.Message msmqMessage = null;
            try
            {
                msmqMessage = this.msmqQueue.EndPeek(result);
            }
            catch (MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
                {
                    this.MsmqPeekBegin();
                    return;
                }
            }

            if (msmqMessage != null)
            {
                var Message = MsmqHelper.UnpackServiceBusMessageFromMsmqMessage(msmqMessage);
                // Clone Service Bus message in case we need to deadletter it.
                var serviceBusDeadletterMessage = Message.Clone();

                Trace.TraceInformation("DurableSender: Enqueue message {0} into Service Bus.", msmqMessage.Label);
                switch (this.SendMessageToServiceBus(Message))
                {
                case SendResult.Success:     // Message was successfully sent to Service Bus. Remove MSMQ message from MSMQ queue.
                    Trace.TraceInformation("DurableSender: Service Bus send operation completed.");
                    this.msmqQueue.BeginReceive(TimeSpan.FromSeconds(60), null, this.MsmqOnReceiveComplete);
                    break;

                case SendResult.WaitAndRetry:     // Service Bus is temporarily unavailable. Wait.
                    Trace.TraceWarning("DurableSender: Service Bus is temporarily unavailable.");
                    this.waitAfterErrorTimer = new Timer(
                        this.ResumeSendingMessagesToServiceBus,
                        null,
                        WaitTimeAfterServiceBusReturnsAnIntermittentErrorInSeconds * 1000,
                        Timeout.Infinite);
                    break;

                case SendResult.PermanentFailure:     // Permanent error. Deadletter MSMQ message.
                    Trace.TraceError("DurableSender: Permanent error when sending message to Service Bus. Deadletter message.");
                    var msmqDeadletterMessage = MsmqHelper.PackServiceBusMessageIntoMsmqMessage(serviceBusDeadletterMessage);
                    try
                    {
                        this.SendtoMsmq(this.msmqDeadletterQueue, msmqDeadletterMessage);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError(
                            "DurableSender: Failure when sending message {0} to deadletter queue {1}: {2} {3}",
                            msmqDeadletterMessage.Label, this.msmqDeadletterQueue.FormatName,
                            ex.GetType(),
                            ex.Message);
                    }
                    this.msmqQueue.BeginReceive(TimeSpan.FromSeconds(60), null, this.MsmqOnReceiveComplete);
                    break;
                }
            }
        }
        public DurableSender(string connectionString, string serviceBusQueueName)
        {
            // Create a Service Bus queue client to send messages to the Service Bus queue.
            this.queueClient = new QueueClient(connectionString, serviceBusQueueName);

            // Create MSMQ queue if it doesn't exit. If it does, open the existing MSMQ queue.
            this.msmqQueue = MsmqHelper.GetMsmqQueue(MsmqHelper.CreateMsmqQueueName("", serviceBusQueueName, "SEND"));

            // Create MSMQ deadletter queue if it doesn't exit. If it does, open the existing MSMQ deadletter queue.
            this.msmqDeadletterQueue = MsmqHelper.GetMsmqQueue(MsmqHelper.CreateMsmqQueueName("", serviceBusQueueName, "SEND_DEADLETTER"));

            // Start receiving messages from the MSMQ queue.
            this.MsmqPeekBegin();
        }
Exemple #3
0
        public DurableSender(MessagingFactory messagingFactory, string serviceBusQueueName)
        {
            // Create a Service Bus queue client to send messages to the Service Bus queue.
            this.queueClient = messagingFactory.CreateQueueClient(serviceBusQueueName);

            // Create MSMQ queue if it doesn't exit. If it does, open the existing MSMQ queue.
            this.msmqQueue = MsmqHelper.GetMsmqQueue(MsmqHelper.CreateMsmqQueueName(messagingFactory.Address.DnsSafeHost, serviceBusQueueName, "SEND"));

            // Create MSMQ deadletter queue if it doesn't exit. If it does, open the existing MSMQ deadletter queue.
            this.msmqDeadletterQueue = MsmqHelper.GetMsmqQueue(MsmqHelper.CreateMsmqQueueName(messagingFactory.Address.DnsSafeHost, serviceBusQueueName, "SEND_DEADLETTER"));

            // Start receiving messages from the MSMQ queue.
            this.MsmqPeekBegin();
        }
        public void Send(Microsoft.Azure.ServiceBus.Message message)
        {
            var msmqMessage = MsmqHelper.PackServiceBusMessageIntoMsmqMessage(message);

            this.SendtoMsmq(this.msmqQueue, msmqMessage);
        }
Exemple #5
0
        public void Send(BrokeredMessage brokeredMessage)
        {
            var msmqMessage = MsmqHelper.PackServiceBusMessageIntoMsmqMessage(brokeredMessage);

            this.SendtoMsmq(this.msmqQueue, msmqMessage);
        }