コード例 #1
0
ファイル: ServiceBusSender.cs プロジェクト: ostat/Beef
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusSender"/> using the specified <see cref="AzureServiceBus.ServiceBusClient"/> where the queue will be inferred from the <see cref="EventMetadata.Subject"/>
 /// using <see cref="CreateQueueName"/> (consider setting the underlying <see cref="AzureServiceBus.ServiceBusClientOptions.RetryOptions"/>) to allow for transient errors).
 /// </summary>
 /// <param name="client">The <see cref="AzureServiceBus.ServiceBusClient"/>.</param>
 /// <param name="removeKeyFromSubject">Indicates whether to remove the key queue name from the <see cref="EventMetadata.Subject"/>. This is achieved by removing the last part (typically the key) to provide the base path;
 /// for example a Subject of <c>Beef.Demo.Person.1234</c> would result in <c>Beef.Demo.Person</c>.</param>
 /// <param name="invoker">Enables the <see cref="Invoker"/> to be overridden. Defaults to <see cref="ServiceBusSenderInvoker"/>.</param>
 public ServiceBusSender(AzureServiceBus.ServiceBusClient client, bool removeKeyFromSubject = false, ServiceBusSenderInvoker?invoker = null)
 {
     _client = Check.NotNull(client, nameof(client));
     _removeKeyFromSubject = removeKeyFromSubject;
     _invoker      = invoker ?? new ServiceBusSenderInvoker();
     SubjectFormat = ActionFormat = EventStringFormat.Lowercase;
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusSessionProcessor"/> class for use with derived types.
 /// </summary>
 /// <param name="client">The client instance to use for the processor.</param>
 /// <param name="topicName">The topic to create a processor for.</param>
 /// <param name="subscriptionName">The subscription to create a processor for.</param>
 /// <param name="options">The set of options to use when configuring the processor.</param>
 protected ServiceBusSessionProcessor(ServiceBusClient client, string topicName, string subscriptionName, ServiceBusSessionProcessorOptions options) :
     this(client?.Connection, EntityNameFormatter.FormatSubscriptionPath(topicName, subscriptionName), options)
 {
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusSessionProcessor"/> class for use with derived types.
 /// </summary>
 /// <param name="client">The client instance to use for the processor.</param>
 /// <param name="queueName">The queue to create a processor for.</param>
 /// <param name="options">The set of options to use when configuring the processor.</param>
 protected ServiceBusSessionProcessor(ServiceBusClient client, string queueName, ServiceBusSessionProcessorOptions options) :
     this(client?.Connection, queueName, options)
 {
 }
コード例 #4
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();
            }
        }
コード例 #5
0
ファイル: ServiceBusSender.cs プロジェクト: ostat/Beef
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusSender"/> using the specified <see cref="AzureServiceBus.ServiceBusClient"/> and queue (or topic) name (consider setting the underlying
 /// <see cref="AzureServiceBus.ServiceBusClientOptions.RetryOptions"/>) to allow for transient errors).
 /// </summary>
 /// <param name="client">The <see cref="AzureServiceBus.ServiceBusClient"/>.</param>
 /// <param name="queueName">The queue (or topic) name.</param>
 /// <param name="invoker">Enables the <see cref="Invoker"/> to be overridden; defaults to <see cref="ServiceBusSenderInvoker"/>.</param>
 public ServiceBusSender(AzureServiceBus.ServiceBusClient client, string queueName, ServiceBusSenderInvoker?invoker = null)
     : this(client, false, invoker) => QueueName = Check.NotEmpty(queueName, nameof(queueName));