DeserializeMessageHeaders() static private method

static private DeserializeMessageHeaders ( Message m ) : string>.Dictionary
m Message
return string>.Dictionary
        async Task TrySendDelayedMessageToErrorQueue(DelayedMessage timeout, Exception exception, CancellationToken cancellationToken)
        {
            try
            {
                bool success = await delayedMessageStore.Remove(timeout, cancellationToken).ConfigureAwait(false);

                if (!success)
                {
                    // Already dispatched
                    return;
                }

                Dictionary <string, string> headersAndProperties = MsmqUtilities.DeserializeMessageHeaders(timeout.Headers);

                ExceptionHeaderHelper.SetExceptionHeaders(headersAndProperties, exception);
                headersAndProperties[FaultsHeaderKeys.FailedQ] = timeoutsQueueTransportAddress;
                foreach (KeyValuePair <string, string> pair in faultMetadata)
                {
                    headersAndProperties[pair.Key] = pair.Value;
                }

                Log.InfoFormat("Move {0} to error queue", timeout.MessageId);
                using (var transportTx = new TransactionScope(txOption, transactionOptions, TransactionScopeAsyncFlowOption.Enabled))
                {
                    var transportTransaction = new TransportTransaction();
                    transportTransaction.Set(Transaction.Current);

                    var outgoingMessage    = new OutgoingMessage(timeout.MessageId, headersAndProperties, timeout.Body);
                    var transportOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(errorQueue));
                    await dispatcher.Dispatch(new TransportOperations(transportOperation), transportTransaction, CancellationToken.None)
                    .ConfigureAwait(false);

                    transportTx.Complete();
                }
            }
            catch (OperationCanceledException) when(cancellationToken.IsCancellationRequested)
            {
                //Shutting down
                Log.Debug("Aborted sending delayed message to error queue due to shutdown.");
            }
            catch (Exception ex)
            {
                Log.Error($"Failed to move delayed message {timeout.MessageId} to the error queue {errorQueue} after {timeout.NumberOfRetries} failed attempts at dispatching it to the destination", ex);
            }
        }
Beispiel #2
0
        public void SaveMessageHeadersSavesNewHeaders()
        {
            var message    = new Message();
            var newHeaders = new Dictionary <string, string>
            {
                { "key1", "value1" },
                { "key2", "value2" }
            };

            MsmqUtilities.SaveMessageHeaders(newHeaders, message);

            Assert.True(message.Extension.Length == 325);

            var deserializedHeaders = MsmqUtilities.DeserializeMessageHeaders(message);

            Assert.True(deserializedHeaders.Count == 2);

            deserializedHeaders.TryGetValue("key1", out var value);
            Assert.Equal("value1", value);

            deserializedHeaders.TryGetValue("key2", out value);
            Assert.Equal("value2", value);
        }