static async Task MainAsync() { var serviceBusConnection = "your-connection-string"; var knightBusHost = new KnightBusHost() //Enable the ServiceBus Transport .UseTransport(new ServiceBusTransport(serviceBusConnection)) .Configure(configuration => configuration //Register our message processors without IoC using the standard provider .UseDependencyInjection(new StandardDependecyInjection() .RegisterProcessor(new SampleServiceBusMessageProcessor()) .RegisterProcessor(new SampleServiceBusEventProcessor())) ); //Start the KnightBus Host, it will now connect to the ServiceBus and listen to the SampleServiceBusMessageMapping.QueueName await knightBusHost.StartAsync(new CancellationToken()); //Initiate the client var client = new KnightBus.Azure.ServiceBus.ServiceBus(new ServiceBusConfiguration(serviceBusConnection)); //Send some Messages and watch them print in the console for (var i = 0; i < 10; i++) { await client.SendAsync(new SampleServiceBusMessage { Message = $"Hello from command {i}" }); } for (var i = 0; i < 10; i++) { await client.PublishEventAsync(new SampleServiceBusEvent { Message = $"Hello from event {i}" }); } Console.ReadKey(); }
static async Task MainAsync(string[] args) { var connectionString = ""; var container = new Container { Options = { DefaultScopedLifestyle = new AsyncScopedLifestyle() } }; var host = new KnightBusHost() .Configure(conf => conf.UseScheduling() .UseSimpleInjector(container) .RegisterSchedules(Assembly.GetExecutingAssembly()) .UseBlobStorageLockManager(connectionString) ); container.Verify(); await host.StartAndBlockAsync(CancellationToken.None); }
static async Task MainAsync() { var storageConnection = "your-connection-string"; //Initiate the client var client = new StorageBus(new StorageBusConfiguration(storageConnection)); client.EnableAttachments(new BlobStorageMessageAttachmentProvider(storageConnection)); var knightBusHost = new KnightBusHost() //Enable the StorageBus Transport .UseTransport(new StorageTransport(storageConnection) //Enable attachments on the transport using Azure Blobs .UseBlobStorageAttachments(storageConnection)) .Configure(configuration => configuration //Allow message processors to run in Singleton state using Azure Blob Locks .UseBlobStorageLockManager(storageConnection) //Register our message processors without IoC using the standard provider .UseDependencyInjection(new StandardDependecyInjection() .RegisterProcessor(new SampleStorageBusMessageProcessor()) .RegisterProcessor(new SampleSagaMessageProcessor(client)) ) //Enable Saga support using the table storage Saga store .EnableSagas(new StorageTableSagaStore(storageConnection)) ); //Start the KnightBus Host, it will now connect to the StorageBus and listen to the SampleStorageBusMessageMapping.QueueName await knightBusHost.StartAsync(CancellationToken.None); //Send some Messages and watch them print in the console for (var i = 0; i < 10; i++) { await client.SendAsync(new SampleStorageBusMessage { Message = $"Hello from command {i}", Attachment = new MessageAttachment($"file{i}.txt", "text/plain", new MemoryStream(Encoding.UTF8.GetBytes($"this is a stream from Message {i}"))) }); } await client.SendAsync(new SampleSagaStartMessage { Message = "This is a saga start message" }); Console.ReadKey(); }
static async Task MainAsync() { var redisConnection = "string"; var multiplexer = ConnectionMultiplexer.Connect(redisConnection); //Initiate the client var client = new RedisBus(new RedisConfiguration(redisConnection)); client.EnableAttachments(new RedisAttachmentProvider(multiplexer, new RedisConfiguration(redisConnection))); var knightBusHost = new KnightBusHost() //Enable the Redis Transport .UseTransport(new RedisTransport(redisConnection)) .Configure(configuration => configuration //Enable reading attachments from Redis .UseRedisAttachments(multiplexer, new RedisConfiguration(redisConnection)) //Enable the saga store .UseRedisSagaStore(multiplexer, new RedisConfiguration(redisConnection)) //Register our message processors without IoC using the standard provider .UseDependencyInjection(new StandardDependecyInjection() .RegisterProcessor(new SampleRedisMessageProcessor()) .RegisterProcessor(new SampleRedisAttachmentProcessor()) .RegisterProcessor(new RedisEventProcessor()) .RegisterProcessor(new RedisEventProcessorTwo()) .RegisterProcessor(new RedisEventProcessorThree()) .RegisterProcessor(new RedisSagaProcessor(client)) ) .AddMiddleware(new PerformanceLogging()) ); //Start the KnightBus Host, it will now connect to the Redis and listen await knightBusHost.StartAsync(CancellationToken.None); //Start the saga await client.SendAsync(new SampleRedisSagaStarterCommand()); //Send some Messages and watch them print in the console var messageCount = 10; var sw = new Stopwatch(); var commands = Enumerable.Range(0, messageCount).Select(i => new SampleRedisCommand { Message = $"Hello from command {i}" }).ToList(); sw.Start(); await client.SendAsync <SampleRedisCommand>(commands); Console.WriteLine($"Elapsed {sw.Elapsed}"); Console.ReadKey(); //var attachmentCommands = Enumerable.Range(0, 10).Select(i => new SampleRedisAttachmentCommand() //{ // Message = $"Hello from command with attachment {i}", // Attachment = new MessageAttachment($"file{i}.txt", "text/plain", new MemoryStream(Encoding.UTF8.GetBytes($"this is a stream from Message {i}"))) //}).ToList(); //await client.SendAsync<SampleRedisAttachmentCommand>(attachmentCommands); //var events = Enumerable.Range(0, 10).Select(i => new SampleRedisEvent //{ // Message = $"Hello from event {i}" //}).ToList(); //await client.PublishAsync<SampleRedisEvent>(events); Console.ReadKey(); }