Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }