public void TestInitialize() { _host = new ServiceHost(new OneWayService(_processorFake, _errorProcessorFake)); const string serviceAddress = "amqp://localhost/myQueue?routingKey=OneWayService"; const string serviceAddress2 = "amqp://localhost/myQueue?routingKey=OneWayService2"; var binding = new RabbitMQBinding { AutoBindExchange = "amq.direct", // If not null, queue will be automatically binded to the exchange using provided routingKey (if any) ExactlyOnce = false, // Non-transactional consumption, OneWayOnly = true, // Use False only if calback communication required //TTL = 1000, // Message time to leave in miliseconds //PersistentDelivery = true // If true, every message will be written to disk on rabbitMQ broker side before dispatching to the destination(s) }; _host.AddServiceEndpoint(typeof(IOneWayService), binding, serviceAddress); _host.AddServiceEndpoint(typeof(IOneWayService2), binding, serviceAddress2); _host.Open(); const string clientAddress = "amqp://localhost/amq.direct?routingKey=OneWayService"; _channelFactory = new ChannelFactory <IOneWayService>(new RabbitMQBinding { OneWayOnly = true }, clientAddress); _channelFactory.Open(); }
public RabbitMQBus(string busId = null, string host = null, int port = 0, string exchange = null, bool exactlyOnce = false, MessageFormat messageFormat = MessageFormat.Text, XmlDictionaryReaderQuotas readerQuotas = null, bool mandatory = false) : base(busId) { RabbitMQBusConfigSectionHandler section = ConfigurationManager.GetSection(RabbitMQBusConfigSectionHandler.SectionName) as RabbitMQBusConfigSectionHandler; _host = GetPropertyValue(host, "localhost", section, s => s.BrokerHost); _port = GetPropertyValue(port, 5672, section, s => s.Port); _exchange = GetPropertyValue(exchange, "amq.headers", section, s => s.Exchange); readerQuotas = GetPropertyValue(readerQuotas, null, section, s => new XmlDictionaryReaderQuotas { MaxArrayLength = s.ReaderQuotas.MaxArrayLength, MaxBytesPerRead = s.ReaderQuotas.MaxBytesPerRead, MaxDepth = s.ReaderQuotas.MaxDepth, MaxNameTableCharCount = s.ReaderQuotas.MaxNameTableCharCount, MaxStringContentLength = s.ReaderQuotas.MaxStringContentLength }); _binding = new RabbitMQBinding { ApplicationId = busId, OneWayOnly = true, ExactlyOnce = exactlyOnce, PersistentDelivery = false, HeaderNamespace = MessagingConstants.Namespace.MessageBus, MessageFormat = messageFormat, ReaderQuotas = readerQuotas, Mandatory = mandatory }; }
/// <summary> /// Runs this instance. /// </summary> private void Run() { Console.WriteLine("Run a ServiceHost via programmatic configuration..."); using (ServiceHost serviceHost = new ServiceHost(typeof(Calculator), new Uri("soap.amqp:///"))) { var serviceEndpoint = serviceHost.AddServiceEndpoint( typeof(ICalculator), new RabbitMQBinding( "localhost", 5672, "guest", "guest", "/", 8192, Protocols.AMQP_0_9_1) { OneWayOnly = false }, "Calculator"); ////serviceEndpoint.Behaviors.Add(new RabbitMqEndpointBehavior(null)); Console.WriteLine("Num. behaviors: {0}", serviceEndpoint.Behaviors.Count); serviceHost.Open(); Console.WriteLine("The service is opened, press ENTER to follow next instructions..."); ////Console.ReadLine(); var proxyBinding = new RabbitMQBinding( "localhost", 5672, "guest", "guest", "/", 8192, Protocols.AMQP_0_9_1) { OneWayOnly = false } ; var endpoint = new EndpointAddress("soap.amqp:///Calculator"); using (var proxy = new CalculatorProxy(proxyBinding, endpoint)) { ////proxy.Endpoint.Behaviors.Add(new RabbitMqEndpointBehavior(null)); var res = proxy.Add(4, 5); Console.WriteLine(res); Console.WriteLine("Type name: {0}", proxy.PrintTypeName(new Person())); Console.WriteLine("Type name: {0}", proxy.PrintTypeName(new Student())); } Console.ReadLine(); } }
public void TwoWay() { var host = new ServiceHost(typeof(Calculator), new Uri("soap.amqp:///")); var binding = new RabbitMQBinding(Constants.HostName, Constants.MainPort); host.AddServiceEndpoint(typeof(ICalculator), binding, "Calculator"); host.Open(); var client = ChannelFactory <ICalculator> .CreateChannel(binding, new EndpointAddress("soap.amqp:///Calculator")); Assert.AreEqual(3, client.Add(1, 2)); host.Close(); }
public void TestInitialize() { _ev = new ManualResetEvent(false); const string clientAddress = "amqp://localhost/amq.direct?routingKey=NoSuchRoute"; _binding = new RabbitMQBinding { OneWayOnly = true, ApplicationId = "MyApp", Mandatory = true }; _channelFactory = _binding.BuildChannelFactory <IOutputChannel>(this); _channelFactory.Open(); _outputChannel = _channelFactory.CreateChannel(new EndpointAddress(clientAddress)) as RabbitMQTransportOutputChannel; _outputChannel.Open(); }
public void Duplex() { var host = new ServiceHost(typeof(OrderService), new Uri("soap.amqp:///")); var binding = new RabbitMQBinding(Constants.HostName, Constants.MainPort); host.AddServiceEndpoint(typeof(IOrderService), binding, "OrderService"); host.Open(); var callback = new OrderCallback(); var client = DuplexChannelFactory <IOrderService> .CreateChannel(callback, binding, new EndpointAddress("soap.amqp:///OrderService")); client.Order(); callback.Semaphore.WaitOne(500); Assert.IsTrue(callback.Completed); host.Close(); }
public void OneWay() { var host = new ServiceHost(typeof(Logger), new Uri("soap.amqp:///")); var binding = new RabbitMQBinding(Constants.HostName, Constants.MainPort) { OneWayOnly = true }; host.AddServiceEndpoint(typeof(ILogger), binding, "Log"); host.Open(); var client = ChannelFactory <ILogger> .CreateChannel(binding, new EndpointAddress("soap.amqp:///Log")); client.Log("ciao"); Logger.Semaphore.WaitOne(500); Assert.AreEqual("ciao", Logger.LastLogged); host.Close(); }
public static Binding GetBinding() { var binding = new RabbitMQBinding("localhost", 5672, "guest", "guest", "/", 8192, Protocols.AMQP_0_9_1); return(binding); }