static async Task Main(string[] args) { Console.Title = "Samples.Azure.ServiceBus.Bridge"; var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString"); if (string.IsNullOrWhiteSpace(connectionString)) { throw new Exception("Could not read the 'AzureServiceBus.ConnectionString' environment variable. Check the sample prerequisites."); } #region bridge-general-configuration var bridgeConfiguration = Bridge .Between <MsmqTransport>("Bridge-MSMQ") .And <AzureServiceBusTransport>("Bridge-ASB", transport => { //Prevents ASB from using TransactionScope transport.Transactions(TransportTransactionMode.ReceiveOnly); transport.ConnectionString(connectionString); var topology = transport.UseEndpointOrientedTopology(); topology.RegisterPublisher(typeof(OtherEvent), "Samples.Azure.ServiceBus.AsbEndpoint"); }); bridgeConfiguration.AutoCreateQueues(); bridgeConfiguration.UseSubscriptionPersistece <InMemoryPersistence>((configuration, persistence) => { }); bridgeConfiguration.TypeGenerator.RegisterKnownType(typeof(OtherEvent)); #endregion #region resubscriber var resubscriber = await Resubscriber <MsmqTransport> .Create( inputQueueName : "Bridge-MSMQ", delay : TimeSpan.FromSeconds(10), configureTransport : t => { }); bridgeConfiguration.InterceptForawrding(resubscriber.InterceptMessageForwarding); #endregion #region bridge-execution var bridge = bridgeConfiguration.Create(); await bridge.Start().ConfigureAwait(false); await resubscriber.Start().ConfigureAwait(false); Console.WriteLine("Press any key to exit"); Console.ReadKey(); await resubscriber.Stop().ConfigureAwait(false); await bridge.Stop().ConfigureAwait(false); #endregion }
static async Task <List <MessageContext> > RunResubscriberOnce(params MessageContext[] input) { await Cleanup("ResubscriberTest", "ResubscriberTest.Resubscriber", "poison").ConfigureAwait(false); var done = new TaskCompletionSource <bool>(); var output = new List <MessageContext>(); var listenerConfig = RawEndpointConfiguration.Create("ResubscriberTest", (context, dispatcher) => { if (context.Headers[Headers.SubscriptionMessageType] == "stop") { done.SetResult(true); } else { output.Add(context); } return(Task.CompletedTask); }, "poison"); listenerConfig.UseTransport <MsmqTransport>(); listenerConfig.LimitMessageProcessingConcurrencyTo(1); listenerConfig.AutoCreateQueue(); var listener = await RawEndpoint.Start(listenerConfig); var resubscriber = await Resubscriber <MsmqTransport> .Create("ResubscriberTest", TimeSpan.FromSeconds(3), t => { }); foreach (var messageContext in input) { await resubscriber.InterceptMessageForwarding("ResubscriberTest", messageContext, NoopDispatch, NoopForward).ConfigureAwait(false); } await resubscriber.InterceptMessageForwarding("ResubscriberTest", CreateTerminatingContext(), NoopDispatch, NoopForward); await resubscriber.Start(); await done.Task; await resubscriber.Stop(); await listener.Stop(); return(output); }
static async Task Main(string[] args) { Console.Title = "Samples.Azure.ServiceBus.Bridge"; var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString"); if (string.IsNullOrWhiteSpace(connectionString)) { throw new Exception("Could not read the 'AzureServiceBus.ConnectionString' environment variable. Check the sample prerequisites."); } // TODO: ASB requires serializer to be registered. // Currently, there's no way to specify serialization for the bridged endpoints // endpointConfiguration.UseSerialization<T>(); #region bridge-general-configuration var bridgeConfiguration = Bridge .Between <MsmqTransport>("Bridge-MSMQ") .And <AzureServiceBusTransport>("Bridge-ASB", transport => { //Prevents ASB from using TransactionScope transport.Transactions(TransportTransactionMode.ReceiveOnly); transport.ConnectionString(connectionString); var settings = transport.GetSettings(); var serializer = Tuple.Create(new NewtonsoftSerializer() as SerializationDefinition, new SettingsHolder()); settings.Set("MainSerializer", serializer); var topology = transport.UseEndpointOrientedTopology(); topology.RegisterPublisher(typeof(OtherEvent), "Samples.Azure.ServiceBus.AsbEndpoint"); }); bridgeConfiguration.AutoCreateQueues(); bridgeConfiguration.UseSubscriptionPersistence(new InMemorySubscriptionStorage()); #endregion #region resubscriber var resubscriber = await Resubscriber <MsmqTransport> .Create( inputQueueName : "Bridge-MSMQ", delay : TimeSpan.FromSeconds(10), configureTransport : t => { }); bridgeConfiguration.InterceptForwarding(resubscriber.InterceptMessageForwarding); #endregion #region bridge-execution var bridge = bridgeConfiguration.Create(); await bridge.Start().ConfigureAwait(false); await resubscriber.Start().ConfigureAwait(false); Console.WriteLine("Press any key to exit"); Console.ReadKey(); await resubscriber.Stop().ConfigureAwait(false); await bridge.Stop().ConfigureAwait(false); #endregion }
public async Task <ComponentRunner> CreateRunner(RunDescriptor run) { resubscriber = await Resubscriber <TestTransport> .Create(inputQueue, TimeSpan.FromSeconds(3), extensions => { extensions.ConfigureNoNativePubSubBrokerA(); }); return(new Runner(resubscriber)); }