public Message2(string title, int height) { Title = title; Height = height; InnerMessage = new Message1(title + title, height + height); }
public void SimpleTest() { var inputQueueName1 = new TransportEndpointAddress(Guid.NewGuid().ToString()); var inputQueueName2 = new TransportEndpointAddress(Guid.NewGuid().ToString()); ServiceBusConfiguration config1 = null; ServiceBusConfiguration config2 = null; try { var unity = new UnityContainer(); var tracker = new Tracker(); unity.RegisterInstance(tracker); var bus1 = ServiceBus.Create(c => c .SetServiceLocator(new UnityServiceLocator(unity)) .MsmqTransport() .SetInputQueue(inputQueueName1.GetFriendlyName()) .AddEndpoint("Paralect.ServiceBus.Test.Messages", inputQueueName2.GetFriendlyName()) .Out(out config1) ); var bus2 = ServiceBus.Create(c => c .SetServiceLocator(new UnityServiceLocator(unity)) .MsmqTransport() .SetInputQueue(inputQueueName2.GetFriendlyName()) .AddEndpoint("Paralect.ServiceBus.Test.Messages", inputQueueName1.GetFriendlyName()) .Dispatcher(d => d .AddHandlers(Assembly.GetExecutingAssembly()) .AddInterceptor(typeof(FirstInterceptor)) .AddInterceptor(typeof(SecondInterceptor)) ) .Out(out config2) ); using (bus1) using (bus2) { bus1.Run(); bus2.Run(); var msg = new Message1("Hello", 2012); bus1.Send(msg); bus2.Wait(); bus1.Wait(); Assert.AreEqual(1, tracker.Handlers.Count); Assert.AreEqual(2, tracker.Interceptors.Count); Assert.AreEqual(typeof(Message1), tracker.Handlers[0]); Assert.AreEqual(typeof(FirstInterceptor), tracker.Interceptors[0]); Assert.AreEqual(typeof(SecondInterceptor), tracker.Interceptors[1]); } } catch (Exception ex) { var z = 45; throw; } finally { var queueProvider1 = TransportRegistry.GetQueueProvider(inputQueueName1); queueProvider1.DeleteEndpoint(config1.InputQueue); queueProvider1.DeleteEndpoint(config1.ErrorQueue); var queueProvider2 = TransportRegistry.GetQueueProvider(inputQueueName2); queueProvider2.DeleteEndpoint(config2.InputQueue); queueProvider2.DeleteEndpoint(config2.ErrorQueue); } }
private void TestTwoBus(Action<ServiceBusConfiguration> configModification1, Action<ServiceBusConfiguration> configModification2) { var inputQueueName1 = new TransportEndpointAddress(Guid.NewGuid().ToString()); var inputQueueName2 = new TransportEndpointAddress(Guid.NewGuid().ToString()); ServiceBusConfiguration config1 = null; ServiceBusConfiguration config2 = null; try { var tracker = new Tracker(); var unity = new UnityContainer() .RegisterInstance(tracker); var bus1 = ServiceBus.Create(c => c .SetServiceLocator(new UnityServiceLocator(unity)) .SetInputQueue(inputQueueName1.GetFriendlyName()) .AddEndpoint("Paralect.ServiceBus.Test.Messages", inputQueueName2.GetFriendlyName()) .Modify(configModification1) .Out(out config1) ); var bus2 = ServiceBus.Create(c => c .SetServiceLocator(new UnityServiceLocator(unity)) .SetInputQueue(inputQueueName2.GetFriendlyName()) .AddEndpoint("Paralect.ServiceBus.Test.Messages", inputQueueName1.GetFriendlyName()) .Dispatcher(d => d .AddHandlers(Assembly.GetExecutingAssembly()) ) .Out(out config2) .Modify(configModification2) ); using (bus1) using (bus2) { bus1.Run(); bus2.Run(); var msg = new Message1("Hello", 2010); var msg2 = new Message1("Hello2", 2010); bus1.Send(msg); bus2.Send(msg2); bus2.Wait(); bus1.Wait(); } Assert.AreEqual(1, tracker.Handlers.Count); Assert.AreEqual(typeof(Message1), tracker.Handlers[0]); } finally { var queueProvider1 = TransportRegistry.GetQueueProvider(inputQueueName1); queueProvider1.DeleteEndpoint(config1.InputQueue); queueProvider1.DeleteEndpoint(config1.ErrorQueue); var queueProvider2 = TransportRegistry.GetQueueProvider(inputQueueName2); queueProvider2.DeleteEndpoint(config2.InputQueue); queueProvider2.DeleteEndpoint(config2.ErrorQueue); } }