예제 #1
0
            public void Connect(string connectionString, string eventHubName, string serviceUri, string tenantIdentity, string resourceIdentity, string clientIdentity)
            {
                EventHubName = eventHubName;

                if (!string.IsNullOrEmpty(serviceUri))
                {
                    var tokenCredentials = new AzureServiceTokenProviderCredentials(tenantIdentity, resourceIdentity, clientIdentity);
                    _client = new Azure.Messaging.EventHubs.Producer.EventHubProducerClient(serviceUri, eventHubName, tokenCredentials);
                }
                else if (string.IsNullOrEmpty(eventHubName))
                {
                    _client = new Azure.Messaging.EventHubs.Producer.EventHubProducerClient(connectionString);
                }
                else
                {
                    _client = new Azure.Messaging.EventHubs.Producer.EventHubProducerClient(connectionString, eventHubName);
                }
            }
예제 #2
0
        static async Task Main()
        {
            var cs  = Environment.GetEnvironmentVariable("Beef_EventHubConnectionString");
            var ehc = new AzureEventHubs.EventHubProducerClient(cs);
            var ehp = new EventHubProducer(ehc);

            cs = Environment.GetEnvironmentVariable("Beef_ServiceBusConnectionString");
            var sbsc = new AzureServiceBus.ServiceBusClient(cs);
            var sbs  = new ServiceBusSender(sbsc, "Default");

            Console.WriteLine("Options are:");
            Console.WriteLine(" x - Stop.");
            Console.WriteLine();
            Console.WriteLine("EventHubs...");
            Console.WriteLine(" 1 - Non-subscribed Event.");
            Console.WriteLine(" 2 - Null Identifier.");
            Console.WriteLine(" 3 - Not Found Exception.");
            Console.WriteLine(" 4 - Unhandled Exception.");
            Console.WriteLine(" 5 - Invalid Data.");
            Console.WriteLine(" 6 - Success.");
            Console.WriteLine();
            Console.WriteLine("ServiceBus...");
            Console.WriteLine(" 11 - Non-subscribed Event.");
            Console.WriteLine(" 12 - Null Identifier.");
            Console.WriteLine(" 13 - Not Found Exception.");
            Console.WriteLine(" 14 - Unhandled Exception.");
            Console.WriteLine(" 15 - Invalid Data.");
            Console.WriteLine(" 16 - Success.");
            Console.WriteLine();

            while (true)
            {
                Console.Write("Enter option: ");
                switch (Console.ReadLine())
                {
                case "x":
                    return;

                case "1":
                    ehp.Publish("Something.Random", "Blah");
                    await ehp.SendAsync();

                    break;

                case "2":
                    ehp.Publish("Demo.Robot.Null", "PowerSourceChange");
                    await ehp.SendAsync();

                    break;

                case "3":
                    ehp.PublishValue(new PowerSourceChangeData {
                        RobotId = Guid.NewGuid(), PowerSource = "N"
                    }, "Demo.Robot.???", "PowerSourceChange");
                    await ehp.SendAsync();

                    break;

                case "4":
                    ehp.PublishValue(new PowerSourceChangeData {
                        RobotId = new Guid(88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "N"
                    }, "Demo.Robot.88", "PowerSourceChange");
                    await ehp.SendAsync();

                    break;

                case "5":
                    ehp.PublishValue(new PowerSourceChangeData {
                        RobotId = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "!"
                    }, "Demo.Robot.2", "PowerSourceChange");
                    await ehp.SendAsync();

                    break;

                case "6":
                    var ed = EventData.CreateValueEvent(new PowerSourceChangeData {
                        RobotId = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "N"
                    }, "Demo.Robot.2", "PowerSourceChange");
                    ed.Key          = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                    ed.PartitionKey = PartitionKeyGenerator.Generate(Guid.NewGuid());
                    ehp.Publish(ed);
                    await ehp.SendAsync();

                    break;

                case "11":
                    sbs.Publish("Something.Random", "Blah");
                    await sbs.SendAsync();

                    break;

                case "12":
                    sbs.Publish("Demo.Robot.Null", "PowerSourceChange");
                    await sbs.SendAsync();

                    break;

                case "13":
                    sbs.PublishValue(new PowerSourceChangeData {
                        RobotId = Guid.NewGuid(), PowerSource = "N"
                    }, "Demo.Robot.???", "PowerSourceChange");
                    await sbs.SendAsync();

                    break;

                case "14":
                    sbs.PublishValue(new PowerSourceChangeData {
                        RobotId = new Guid(88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "N"
                    }, "Demo.Robot.88", "PowerSourceChange");
                    await sbs.SendAsync();

                    break;

                case "15":
                    sbs.PublishValue(new PowerSourceChangeData {
                        RobotId = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "!"
                    }, "Demo.Robot.2", "PowerSourceChange");
                    await sbs.SendAsync();

                    break;

                case "16":
                    ed = EventData.CreateValueEvent(new PowerSourceChangeData {
                        RobotId = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "N"
                    }, "Demo.Robot.2", "PowerSourceChange");
                    ed.Key          = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                    ed.PartitionKey = PartitionKeyGenerator.Generate(Guid.NewGuid());
                    sbs.Publish(ed);
                    await sbs.SendAsync();

                    break;
                }

                ehp.Reset();
                sbs.Reset();
            }
        }