public AzureEventHubService() { ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(AppConfig.EventHubConnectionString); builder.TransportType = TransportType.Amqp; MessagingFactory factory = MessagingFactory.CreateFromConnectionString(AppConfig.EventHubConnectionString); _client = factory.CreateEventHubClient(AppConfig.EventHubName); }
public MainPage() { this.InitializeComponent(); builder = new ServiceBusConnectionStringBuilder(this.ConnectionString); builder.TransportType = TransportType.Amqp; factory = MessagingFactory.CreateFromConnectionString(this.ConnectionString); topicClient = factory.CreateTopicClient("topic2"); subClient = factory.CreateSubscriptionClient("topic2", "sub1", ReceiveMode.PeekLock); }
// 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(); }
/// <summary> /// Constructor /// </summary> /// <param name="deviceName">Device name</param> /// <param name="deviceId">Device ID</param> /// <param name="connectionString">Connection string to Service Bus namespace</param> /// <param name="eventhubentity">Event Hub entity name</param> public IoTClientBase(string deviceName, string deviceId, string connectionString, string eventhubentity) { this.DeviceName = deviceName; this.DeviceId = deviceId; this.queue = new Queue<EventData>(); this.queueEvent = new AutoResetEvent(false); ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(connectionString); builder.TransportType = TransportType.Amqp; this.factory = MessagingFactory.CreateFromConnectionString(builder.ToString()); this.client = this.factory.CreateEventHubClient(eventhubentity); }
public Example2View() { this.InitializeComponent(); builder = new ServiceBusConnectionStringBuilder(this.ConnectionString); builder.TransportType = TransportType.Amqp; factory = MessagingFactory.CreateFromConnectionString(this.ConnectionString); topicClient = factory.CreateTopicClient("topic3"); subClient = factory.CreateSubscriptionClient("topic3", "sub1", ReceiveMode.PeekLock); Task.Run(async () => { await RunAsync(); }); }
public void Scenario1_EventHubSend(string eventHubEntity) { ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(this.ConnectionString); builder.TransportType = TransportType.Amqp; MessagingFactory factory = MessagingFactory.CreateFromConnectionString(this.ConnectionString); EventHubClient client = factory.CreateEventHubClient(eventHubEntity); EventData data = new EventData(Encoding.UTF8.GetBytes("Body")); data.Properties["time"] = DateTime.UtcNow; client.Send(data); client.Close(); factory.Close(); }
public void Scenario12_SubscriptionReceiver(object obj) { Scenarios.TopicSub topicSub = (Scenarios.TopicSub)obj; ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(this.ConnectionString); builder.TransportType = TransportType.Amqp; MessagingFactory factory = MessagingFactory.CreateFromConnectionString(this.ConnectionString); SubscriptionClient client = factory.CreateSubscriptionClient(topicSub.Topic, topicSub.Sub); while (true) { BrokeredMessage request = client.Receive(); request.Complete(); } }
//Receive from a specfic topic's subscription public void SubscriptionReceiver(object obj) { azureConnector.TopicSub topicsub = (azureConnector.TopicSub)obj; ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(SB_CONNECTION_STRING); builder.TransportType = TransportType.Amqp; MessagingFactory factory = MessagingFactory.CreateFromConnectionString(SB_CONNECTION_STRING); SubscriptionClient client = factory.CreateSubscriptionClient(topicsub.Topic, topicsub.Sub); string msg; while (true) { BrokeredMessage request = client.Receive(); if (request.Properties != null) { msg = decodeMsg(request); } request.Complete(); } }
public MainPage() { this.InitializeComponent(); //Amqp.Trace.TraceLevel = Amqp.TraceLevel.Frame | Amqp.TraceLevel.Verbose; //Amqp.Trace.TraceListener = (f, a) => Debug.WriteLine(DateTime.Now.ToString("[hh:ss.fff]") + " " + Fx.Format(f, a)); builder = new ServiceBusConnectionStringBuilder(this.ConnectionString); builder.TransportType = TransportType.Amqp; factory = MessagingFactory.CreateFromConnectionString(this.ConnectionString); topicClient = factory.CreateTopicClient("topic1"); subClient = factory.CreateSubscriptionClient("topic1", "BankerChannel", ReceiveMode.PeekLock); factory.Close(); Task.Run(async () => { await RunAsync(); }); }
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(); }
public static string CreateUsingSharedAccessSignature(Uri endpoint, string entityPath, string publisher, string sharedAccessSignature) { ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder { Endpoint = endpoint, EntityPath = entityPath, Publisher = publisher, SharedAccessSignature = sharedAccessSignature }; return builder.ToString(); }
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(); } }
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(); }
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 void Scenario7_EventHubReceiveFromPartitionOffset(string eventHubEntity, string partitionId, string offset) { ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(this.ConnectionString); builder.TransportType = TransportType.Amqp; MessagingFactory factory = MessagingFactory.CreateFromConnectionString(this.ConnectionString); EventHubClient client = factory.CreateEventHubClient(eventHubEntity); EventHubConsumerGroup group = client.GetDefaultConsumerGroup(); EventHubReceiver receiver = group.CreateReceiver(partitionId, offset); while (true) { EventData data = receiver.Receive(); } receiver.Close(); client.Close(); factory.Close(); }
//Receive from a specfic topic's subscription private void SubscriptionReceiver(object obj) { try { azureConnector.TopicSub topicsub = (azureConnector.TopicSub)obj; ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(SB_CONNECTION_STRING); builder.TransportType = TransportType.Amqp; MessagingFactory factory = MessagingFactory.CreateFromConnectionString(SB_CONNECTION_STRING); SubscriptionClient client = factory.CreateSubscriptionClient(topicsub.Topic, topicsub.Sub); string msg; while (true) { BrokeredMessage request = client.Receive(); if (request != null && request.Properties != null) { msg = decodeMsg(request); recieveMessage(msg); } request.Complete(); } } catch(Exception ex) { Debug.WriteLine("ERROR : " + ex.ToString()); } }