Exemple #1
0
        static void Main(string[] args)
        {
            string sbConnectionString = "Endpoint=sb://miniproject.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=tGkzmzkJl5PqEBSAQxiWA92Dt0wV9HSBOh7QS6k4OGo=";
            string sbQueName          = "recharge";

            try
            {
                queueClient = new Microsoft.Azure.ServiceBus.QueueClient(sbConnectionString, sbQueName);


                var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
                {
                    MaxConcurrentCalls = 1,
                    AutoComplete       = false
                };
                queueClient.RegisterMessageHandler(ReceiveMessagesAsync, messageHandlerOptions);
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.ReadKey();
                queueClient.CloseAsync();
            }
        }
Exemple #2
0
        //--- Send one message
        public async Task PushMessageAsync2_1(string queueName, Message SendMessage)
        {
            try
            {
                await queueClient.SendAsync(SendMessage);

                //---Debug.WriteLine("--->queueClient.SendAsync(SendMessage)");
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                throw;
            }
            finally
            {
                await queueClient.CloseAsync();
            }
        }
Exemple #3
0
        public async Task SendAsync <TMessage>(TMessage message) where TMessage : IBusQueueMessage
        {
            var client = new Microsoft.Azure.ServiceBus.QueueClient(new ServiceBusConnectionStringBuilder(_connectionString)
            {
                EntityPath = message.QueueName
            });

            var serviceBusMessage = _messageFactory.CreateMessage(message);

            await client.SendAsync(serviceBusMessage);

            await client.CloseAsync();
        }
        public async Task UpdateStockAsync(ProductInStockUpdateStockCommand command)
        {
            var queueClient = new Microsoft.Azure.ServiceBus.QueueClient(_connectionString, "order-stock-update");

            // Serialize message
            string body    = JsonSerializer.Serialize(command);
            var    message = new Message(Encoding.UTF8.GetBytes(body));

            // Send the message to the queue
            await queueClient.SendAsync(message);

            // Close
            await queueClient.CloseAsync();
        }
Exemple #5
0
        /// <inheritdoc />
        public async Task SendAsync <TMessage>(TMessage message) where TMessage : IBusQueueMessage
        {
            if (string.IsNullOrEmpty(message.QueueName))
            {
                throw new ApplicationException("Queue name is mandatory");
            }

            var client = new Microsoft.Azure.ServiceBus.QueueClient(new ServiceBusConnectionStringBuilder(_connectionString)
            {
                EntityPath = message.QueueName
            });

            var serviceBusMessage = _messageFactory.CreateMessage(message);

            await client.SendAsync(serviceBusMessage);

            await client.CloseAsync();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            string sbConnectionString = "Endpoint=sb://miniproject.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=tGkzmzkJl5PqEBSAQxiWA92Dt0wV9HSBOh7QS6k4OGo=";
            string sbQueName          = "recharge";
            string messageBody        = string.Empty;

            do
            {
                try
                {
                    Console.WriteLine("----------------------------------------------------");
                    Console.WriteLine("Mobile Recharge information");
                    Console.WriteLine("----------------------------------------------------");
                    Console.WriteLine("Mobile operator list");
                    Console.WriteLine("1. Greemen phone");
                    Console.WriteLine("2. Aktel");
                    Console.WriteLine("3. Banglalink");
                    Console.WriteLine("4. Citycell");
                    Console.WriteLine("----------------------------------------------------");

                    Console.WriteLine("Choose the operator to recharge:");
                    string mobileOperator = Console.ReadLine();
                    Console.WriteLine("Recharge amount:");
                    string amount = Console.ReadLine();
                    Console.WriteLine("Enter mobile number");
                    string moileNo = Console.ReadLine();
                    Console.WriteLine("----------------------------------------------------");

                    switch (mobileOperator)
                    {
                    case "1":
                        mobileOperator = "Greemen phone";
                        break;

                    case "2":
                        mobileOperator = "Aktel";
                        break;

                    case "3":
                        mobileOperator = "Banglalink";
                        break;

                    case "4":
                        mobileOperator = "Citycell";
                        break;

                    default:
                        break;
                    }

                    messageBody = "Operator Name:" + mobileOperator + "\n Phone No:" + moileNo + "\n Amount:" + amount;
                    queueClient = new Microsoft.Azure.ServiceBus.QueueClient(sbConnectionString, sbQueName);

                    var message = new Microsoft.Azure.ServiceBus.Message(Encoding.UTF8.GetBytes(messageBody));
                    Console.WriteLine($"Message Added in Queue: {messageBody}");
                    queueClient.SendAsync(message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    Console.ReadKey();
                    queueClient.CloseAsync();
                }
                Console.WriteLine("Do you want to send more message: y/n");
                s = Console.ReadLine().ToString();
                Console.ReadKey();
            }while (s == "y");
        }