Esempio n. 1
0
        public async Task RunAsync()
        {
            Debug.WriteLine("RunAsync Called");
            BrokeredMessage message = new BrokeredMessage();
            while (true)
            {
                try
                {
                    message = subClient.Receive();

                    Debug.WriteLine("\t message = " + (string) message.Properties["message"]);

                    await this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                    {
                        this.TopicReceived.Text = (string) message.Properties["message"];
                    });

                    message.Complete();
                }
                catch
                {
                    message.Complete();
                    Debug.WriteLine("Caught Exception");
                }
            }
        }
Esempio n. 2
0
        private void TopicSendClick(object sender, RoutedEventArgs e)
        {
            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("Body"));
            BrokeredMessage message = new BrokeredMessage(stream);
            message.Properties["time"] = DateTime.UtcNow;
            message.Properties["message"] = TopicMessage.Text;

            topicClient.Send(message);
        }
Esempio n. 3
0
 private string decodeMsg(BrokeredMessage request)
 {
     byte[] buffer;
     Char[] msg;
     buffer = request.GetBytes();
     Decoder utf8decoder = Encoding.UTF8.GetDecoder();
     int charCount = utf8decoder.GetCharCount(buffer, 0, buffer.Length);
     msg = new Char[charCount];
     utf8decoder.GetChars(buffer, 0, buffer.Length, msg, 0);
     return new string(msg);
 }
Esempio n. 4
0
 // private string SUBSCRIPTION = "";
 // private string SHARED_ACCESS_KEY_NAME = "RootManageSharedAccessKey";
 // private string SHARED_ACCESS_KEY = "ELXXNeA+zNdYw5qVwe6qj8WqrX4AIhjSDW7s0vogPcM=";
 //Send the contents to the service bus's topic
 public void sendSBMessageToTopic(string content, string topic)
 {
     ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(SB_CONNECTION_STRING);
     builder.TransportType = TransportType.Amqp;
     MessagingFactory factory = MessagingFactory.CreateFromConnectionString(SB_CONNECTION_STRING);
     TopicClient client = factory.CreateTopicClient(topic);
     MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
     BrokeredMessage message = new BrokeredMessage(stream);
     message.Properties["time"] = DateTime.UtcNow;
     client.Send(message);
     client.Close();
     factory.Close();
 }
        private void TopicSendClick(object sender, RoutedEventArgs e)
        {
            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("Body"));
            BrokeredMessage message = new BrokeredMessage(stream);
            message.Properties["time"] = DateTime.UtcNow;
            message.Properties["message"] = TopicMessage.Text;
            message.Properties["recipient"] = "Banker";

            /// TRYING TO CUSTOM TIMEOUT
            var tokenSource = new CancellationTokenSource();
            CancellationToken token = tokenSource.Token;
            int timeOut = 1000; // 1000 ms

            try
            {
                var task = Task.Factory.StartNew(() => topicClient.Send(message), token);

                if (!task.Wait(timeOut, token))
                {
                    Debug.WriteLine("The Task timed out!");
                }
            }
            catch
            {
                Debug.WriteLine("Some kind of exception");
            }


            //try
            //{

            //    topicClient.Send(message);
            //}
            //catch (Exception ex)
            //{
            //    Debug.WriteLine("Customer: Timeout Exception: " + ex.Message);
            //}

            TopicMessage.Text = String.Empty;
        }
Esempio n. 6
0
        public void Scenario11_TopicSend(string topic, string subscription1, string subscription2)
        {
            WorkerThread sub1Thread = new WorkerThread(this.Scenario12_SubscriptionReceiver);
            sub1Thread.Start(new Scenarios.TopicSub() { Topic = topic, Sub = subscription1 });

            WorkerThread sub2Thread = new WorkerThread(this.Scenario12_SubscriptionReceiver);
            sub2Thread.Start(new Scenarios.TopicSub() { Topic = topic, Sub = subscription2 });

            ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(this.ConnectionString);
            builder.TransportType = TransportType.Amqp;

            MessagingFactory factory = MessagingFactory.CreateFromConnectionString(this.ConnectionString);

            TopicClient client = factory.CreateTopicClient(topic);

            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("Body"));
            BrokeredMessage message = new BrokeredMessage(stream);
            message.Properties["time"] = DateTime.UtcNow;

            client.Send(message);

            client.Close();
            factory.Close();
        }
Esempio n. 7
0
 /// <summary>
 /// Send message to the queue
 /// </summary>
 /// <param name="message">BrokeredMessage instance to send</param>
 public void Send(BrokeredMessage message)
 {
     this.CreateSender();
     this.Sender.Send(message);
 }
Esempio n. 8
0
        private void Scenario10_QueueReceiver(object obj)
        {
            string queue = (string)obj;

            ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(this.ConnectionString);
            builder.TransportType = TransportType.Amqp;

            MessagingFactory factory = MessagingFactory.CreateFromConnectionString(this.ConnectionString);

            QueueClient client = factory.CreateQueueClient(queue);

            while (true)
            {
                BrokeredMessage request = client.Receive();
                request.Complete();

                MessageSender sender = factory.CreateMessageSender(request.ReplyTo);

                MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("Response"));
                BrokeredMessage response = new BrokeredMessage(stream);
                response.CorrelationId = request.MessageId;
                response.Properties["time"] = DateTime.UtcNow;

                sender.Send(response);

                sender.Close();
            }
        }
Esempio n. 9
0
        public void Scenario9_QueueRequestResponse(string queue, string replyTo)
        {
            WorkerThread receiverThread = new WorkerThread(this.Scenario10_QueueReceiver);
            receiverThread.Start(queue);

            ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(this.ConnectionString);
            builder.TransportType = TransportType.Amqp;

            MessagingFactory factory = MessagingFactory.CreateFromConnectionString(this.ConnectionString);

            MessageSender sender = factory.CreateMessageSender(queue);

            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("Request"));
            BrokeredMessage message = new BrokeredMessage(stream);
            message.MessageId = Guid.NewGuid().ToString();
            message.ReplyTo = replyTo;
            message.Properties["time"] = DateTime.UtcNow;

            sender.Send(message);

            MessageReceiver receiver = factory.CreateMessageReceiver(replyTo);

            BrokeredMessage response = receiver.Receive();
            response.Complete();

            sender.Close();
            receiver.Close();
            factory.Close();
        }
Esempio n. 10
0
        public void Scenario8_QueueSend(string queue)
        {
            ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(this.ConnectionString);
            builder.TransportType = TransportType.Amqp;

            MessagingFactory factory = MessagingFactory.CreateFromConnectionString(this.ConnectionString);

            QueueClient client = factory.CreateQueueClient(queue);

            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("Body"));
            BrokeredMessage message = new BrokeredMessage(stream);
            message.Properties["time"] = DateTime.UtcNow;

            client.Send(message);

            client.Close();
            factory.Close();
        }
        public async Task RunAsync()
        {
            Debug.WriteLine("RunAsync Called");
            BrokeredMessage message = new BrokeredMessage();
            while (true)
            {
                try
                {
                    Debug.WriteLine("Customer: try message recieve");
                    message = subClient.Receive();

                    if(message != null) {
                        Debug.WriteLine("Customer: message received");

                        try
                        {
                            if (message.Properties["recipient"].Equals("Customer"))
                            {
                                Debug.WriteLine("Customer: message = " + (string) message.Properties["message"]);

                                await this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                                {
                                    this.TopicReceived.Text = (string) message.Properties["message"];
                                });
                            }
                        }
                        catch
                        {
                            Debug.WriteLine("Customer: checking message.Properties for key failed");
                        }


                        Debug.WriteLine("Customer: try message complete");
                        message.Complete();
                        Debug.WriteLine("Customer: message complete successful");
                    }
                    else
                    {
                        Debug.WriteLine("Customer: message was null");
                    }
                }
                catch(Exception e)
                {
                    Debug.WriteLine("Customer: Caught Exception: " + e.Message);
                    //message.Complete();
                }
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Send message to the queue
 /// </summary>
 /// <param name="message">BrokeredMessage instance to send</param>
 public void Send(BrokeredMessage message)
 {
     this.CreateSender();
     this.Sender.Send(message);
 }