Exemplo n.º 1
0
        static bool ProcessMessage(QueueMessage message, int?invisibilityTimeout = null)
        {
            var  messageProcessed = false;
            Guid contextId        = message.CorrelationId.HasValue ? message.CorrelationId.Value : Guid.Empty;

            using (var ctx = new CorrelationContext(contextId))
            {
                switch (message.MessageType)
                {
                case MessageTypes.BeginReplicate:
                    messageProcessed = DoReplicateJob(message, invisibilityTimeout);
                    break;

                case MessageTypes.ReplicateProgress:
                    messageProcessed = DoReplicateProgressJob(message, invisibilityTimeout);
                    break;

                case MessageTypes.DeleteReplica:
                    messageProcessed = DoDeleteReplicaJob(message, invisibilityTimeout);
                    break;

                case MessageTypes.Unknown:
                default:
                    DashTrace.TraceWarning("Unable to process unknown message type from async queue [{0}]. Payload: {1}",
                                           message.MessageType,
                                           message.ToString());
                    // Let this message bounce around for a bit - there may be a different version running
                    // on another instance that knows about this message. It will be automatically discarded
                    // after exceeding the deque limit.
                    messageProcessed = false;
                    break;
                }
            }
            return(messageProcessed);
        }
Exemplo n.º 2
0
        private static async Task MainAsync()
        {
            var randomNumber = new Random().Next(1, 100);
            var message      = new QueueMessage()
            {
                SenderName         = GetSenderName(randomNumber),
                Ammount            = randomNumber,
                DestinationAccount = Guid.NewGuid().ToString(),
                DestinationName    = GetDestinationName(randomNumber)
            };

            Console.WriteLine($"Sending message:\n{message.ToString()}");

            // initialize queue client and send message here
            queueClient = new QueueClient(SERVICE_BUS_CONNECTION_STRING, QUEUE_NAME);

            var     serializedMessage = JsonConvert.SerializeObject(message);
            Message messageToSend     = new Message(Encoding.UTF8.GetBytes(serializedMessage));

            try
            {
                await queueClient.SendAsync(messageToSend);
            }
            catch (Exception exception)
            {
                Console.WriteLine($"{DateTime.Now} :: Exception: {exception.Message}");
            }

            await queueClient.CloseAsync();
        }
Exemplo n.º 3
0
        public IPostResponse PostMessage(string queuename, [FromContent] QueueMessage message)
        {
            var queue = ServiceLocator.Current.GetService <IMessageQueue>();

            _log.LogTrace("Queue: " + queuename + "|Message: " + message.ToString());
            queue.Enqueue(queuename, message);
            return(new PostResponse(PostResponse.ResponseStatus.Created));
        }
Exemplo n.º 4
0
        private static async Task MainAsync()
        {
            var randomNumber = new Random().Next(1, 100);
            var message      = new QueueMessage()
            {
                SenderName         = GetSenderName(randomNumber),
                Ammount            = randomNumber,
                DestinationAccount = Guid.NewGuid().ToString(),
                DestinationName    = GetDestinationName(randomNumber)
            };

            Console.WriteLine($"Sending message:\n{message.ToString()}");

            // initialize queue client and send message here
        }
Exemplo n.º 5
0
        private static async Task MainAsync()
        {
            var queueClient = new QueueClient(SERVICE_BUS_CONNECTION_STRING, QUEUE_NAME);

            var randomNumber = new Random().Next(1, 100);
            var message      = new QueueMessage()
            {
                SenderName         = GetSenderName(randomNumber),
                Ammount            = randomNumber,
                DestinationAccount = Guid.NewGuid().ToString(),
                DestinationName    = GetDestinationName(randomNumber)
            };

            var queueMessage = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)));

            Console.WriteLine($"Sending message:\n{message.ToString()}");
            await queueClient.SendAsync(queueMessage);
        }