static void Main(string[] args) { //Create host and register custom transport listener var uri = new Uri(address); var host = new ContainerHost(new List<Uri>() { uri }, null, uri.UserInfo); host.CustomTransports.Add("pipe", NamedPipeTransport.Listener); host.RegisterMessageProcessor(nodeName, new MessageProcessor()); host.Open(); Console.WriteLine("Listener: running"); //Create factory with custom transport factory var factory = new ConnectionFactory(new TransportProvider[] { NamedPipeTransport.Factory }); var connection = factory.CreateAsync(new Address(address)).GetAwaiter().GetResult(); var session = new Session(connection); var sender = new SenderLink(session, "message-client", nodeName); Console.WriteLine("Client: sending a message"); sender.Send(new Message("Hello Pipe!")); sender.Close(); session.Close(); connection.Close(); Console.WriteLine("Client: closed"); host.Close(); Console.WriteLine("Listener: closed"); }
static void Main(string[] args) { string address = "amqp://*****:*****@127.0.0.1:5672"; if (args.Length > 0) { address = args[0]; } // uncomment the following to write frame traces //Trace.TraceLevel = TraceLevel.Frame; //Trace.TraceListener = (f, a) => Console.WriteLine(DateTime.Now.ToString("[hh:ss.fff]") + " " + string.Format(f, a)); Uri addressUri = new Uri(address); ContainerHost host = new ContainerHost(new Uri[] { addressUri }, null, addressUri.UserInfo); host.Open(); Console.WriteLine("Container host is listening on {0}:{1}", addressUri.Host, addressUri.Port); string messageProcessor = "message_processor"; host.RegisterMessageProcessor(messageProcessor, new MessageProcessor()); Console.WriteLine("Message processor is registered on {0}", messageProcessor); string requestProcessor = "request_processor"; host.RegisterRequestProcessor(requestProcessor, new RequestProcessor()); Console.WriteLine("Request processor is registered on {0}", requestProcessor); Console.WriteLine("Press enter key to exist..."); Console.ReadLine(); host.Close(); }
public void ContainerHostWebSocketWildCardAddressTest() { var host = new ContainerHost(new string[] { "ws://+:28080/test/" }); host.Listeners[0].SASL.EnablePlainMechanism("guest", "guest"); host.RegisterMessageProcessor("q1", new TestMessageProcessor()); host.Open(); try { var connection = Connection.Factory.CreateAsync(new Address("ws://*****:*****@localhost:28080/test/")).Result; var session = new Session(connection); var sender = new SenderLink(session, "ContainerHostWebSocketWildCardAddressTest", "q1"); sender.Send(new Message("msg1"), SendTimeout); connection.Close(); } catch { System.Diagnostics.Trace.WriteLine("If the test fails with System.Net.HttpListenerException (0x80004005): Access is denied"); System.Diagnostics.Trace.WriteLine("Run the following command with admin privilege:"); System.Diagnostics.Trace.WriteLine("netsh http add urlacl url=http://+:28080/test/ user=domain\\user"); throw; } finally { host.Close(); } }
public MessageProcessor CreateMessageProcessor(string address) { var messageProcessor = new MessageProcessor(); _host.RegisterMessageProcessor(address, messageProcessor); return(messageProcessor); }
static void Main(string[] args) { //Create host and register custom transport listener var host = new ContainerHost(new Address(address)); host.CustomTransports.Add("pipe", NamedPipeTransport.Listener); host.RegisterMessageProcessor(nodeName, new MessageProcessor()); host.Open(); Console.WriteLine("Listener: running"); //Create factory with custom transport factory var factory = new ConnectionFactory(new TransportProvider[] { NamedPipeTransport.Factory }); var connection = factory.CreateAsync(new Address(address)).GetAwaiter().GetResult(); var session = new Session(connection); var sender = new SenderLink(session, "message-client", nodeName); Console.WriteLine("Client: sending a message"); sender.Send(new Message("Hello Pipe!")); sender.Close(); session.Close(); connection.Close(); Console.WriteLine("Client: closed"); host.Close(); Console.WriteLine("Listener: closed"); }
static void Main(string[] args) { //Create host and register message processor var uri = new Uri(Address); var host = new ContainerHost(new List <Uri>() { uri }, null, uri.UserInfo); host.RegisterMessageProcessor(MsgProcName, new MessageProcessor()); host.Open(); //Create client var connection = new Connection(new Address(Address)); var session = new Session(connection); var sender = new SenderLink(session, "message-client", MsgProcName); //Send message with an object of custom type as the body var person = new Person() { EyeColor = "brown", Height = 175, Weight = 75 }; sender.Send(new Message(person)); sender.Close(); session.Close(); connection.Close(); host.Close(); }
public override void Run() { Uri addressUri = new Uri(this.Args.Address); ContainerHost host = new ContainerHost(new Uri[] { addressUri }, null, addressUri.UserInfo); host.Open(); Console.WriteLine("Container host is listening on {0}:{1}", addressUri.Host, addressUri.Port); host.RegisterMessageProcessor(this.Args.Node, this); Console.WriteLine("Message processor is registered on {0}", this.Args.Node); this.Wait(); host.Close(); }
public override void Run() { Uri addressUri = new Uri(this.Args.Address); X509Certificate2 certificate = Extensions.GetCertificate(addressUri.Scheme, addressUri.Host, this.Args.CertValue); ContainerHost host = new ContainerHost(new Uri[] { addressUri }, certificate, addressUri.UserInfo); host.Open(); Console.WriteLine("Container host is listening on {0}:{1}", addressUri.Host, addressUri.Port); host.RegisterMessageProcessor(this.Args.Node, this); Console.WriteLine("Message processor is registered on {0}", this.Args.Node); this.Wait(); host.Close(); }
static void Main(string[] args) { //Trace.TraceLevel = TraceLevel.Frame; //Trace.TraceListener = (f, a) => Console.WriteLine(DateTime.Now.ToString("[hh:ss.fff]") + " " + string.Format(f, a)); string address = "amqps://localhost:5671"; // start a host with custom SSL and SASL settings Console.WriteLine("Starting server..."); Uri addressUri = new Uri(address); ContainerHost host = new ContainerHost(addressUri); var listener = host.Listeners[0]; listener.SSL.Certificate = GetCertificate("localhost"); listener.SSL.ClientCertificateRequired = true; listener.SSL.RemoteCertificateValidationCallback = ValidateServerCertificate; listener.SASL.EnableExternalMechanism = true; host.Open(); Console.WriteLine("Container host is listening on {0}:{1}", addressUri.Host, addressUri.Port); string messageProcessor = "message_processor"; host.RegisterMessageProcessor(messageProcessor, new MessageProcessor()); Console.WriteLine("Message processor is registered on {0}", messageProcessor); Console.WriteLine("Starting client..."); ConnectionFactory factory = new ConnectionFactory(); factory.SSL.ClientCertificates.Add(GetCertificate("localhost")); factory.SSL.RemoteCertificateValidationCallback = ValidateServerCertificate; factory.SASL.Profile = SaslProfile.External; Console.WriteLine("Sending message..."); Connection connection = factory.CreateAsync(new Address(address)).Result; Session session = new Session(connection); SenderLink sender = new SenderLink(session, "certificate-example-sender", "message_processor"); sender.Send(new Message("hello world")); sender.Close(); session.Close(); connection.Close(); Console.WriteLine("client done"); host.Close(); Console.WriteLine("server stopped"); }
public override Task StartInternalAsync() { var end = new TaskCompletionSource <bool>(); _cancellationRegistration = Token.Register(() => { end.TrySetCanceled(); }); var incommingLink = new IncomingLinkEndpoint(end, _messages); var uri = new Uri("amqp://localhost:" + Settings.Port); _host = new ContainerHost(uri); _host.Open(); _host.RegisterMessageProcessor(uri.AbsolutePath, new MessageProcessor()); _host.RegisterLinkProcessor(new LinkProcessor(incommingLink)); return(end.Task); }
public override void Run() { Uri addressUri = new Uri(this.Args.Address); X509Certificate2 certificate = Extensions.GetCertificate(addressUri.Scheme, addressUri.Host, this.Args.CertValue); ContainerHost host = new ContainerHost(new Uri[] { addressUri }, certificate, addressUri.UserInfo); foreach (var listener in host.Listeners) { listener.BufferManager = this.bufferManager; listener.AMQP.MaxFrameSize = this.Args.MaxFrameSize; } host.Open(); Console.WriteLine("Container host is listening on {0}:{1}", addressUri.Host, addressUri.Port); host.RegisterMessageProcessor(this.Args.Node, this); Console.WriteLine("Message processor is registered on {0}", this.Args.Node); this.Wait(); host.Close(); }
static void Main(string[] args) { //Create host and register message processor var uri = new Uri(Address); var host = new ContainerHost(new List<Uri>() { uri }, null, uri.UserInfo); host.RegisterMessageProcessor(MsgProcName, new MessageProcessor()); host.Open(); //Create client var connection = new Connection(new Address(Address)); var session = new Session(connection); var sender = new SenderLink(session, "message-client", MsgProcName); //Send message with an object of custom type as the body var person = new Person() { EyeColor = "brown", Height = 175, Weight = 75 }; sender.Send(new Message(person)); sender.Close(); session.Close(); connection.Close(); host.Close(); }
public void ContainerHostCustomTransportTest() { string name = "ContainerHostCustomTransportTest"; string address = "pipe://./" + name; ContainerHost host = new ContainerHost(new Uri(address)); host.CustomTransports.Add("pipe", NamedPipeTransport.Listener); host.RegisterMessageProcessor(name, new TestMessageProcessor()); host.Open(); try { var factory = new ConnectionFactory(new TransportProvider[] { NamedPipeTransport.Factory }); var connection = factory.CreateAsync(new Address(address)).GetAwaiter().GetResult(); var session = new Session(connection); var sender = new SenderLink(session, name, name); sender.Send(new Message("msg1"), SendTimeout); connection.Close(); } finally { host.Close(); } }
public void RegisterMessageProcessor(string address, Action <MessageContext> handler) { containerHost.RegisterMessageProcessor(address, new TestMessageProcessor(handler)); }
static void Main(string[] args) { //Create host and register message processor var uri = new Uri(Address); var host = new ContainerHost(new List <Uri>() { uri }, null, uri.UserInfo); host.RegisterMessageProcessor(MsgProcName, new MessageProcessor()); host.Open(); //Create client var connection = new Connection(new Address(Address)); var session = new Session(connection); var sender = new SenderLink(session, "message-client", MsgProcName); //Send message with an object of the base class as the body var person = new Person() { EyeColor = "brown", Height = 175, Weight = 75 }; SendMessage(sender, "Person", person); //Send message with an object of a derived class as the body var student = new Student() { GPA = 4.8, Address = new ListAddress() { Street = "123 Main St.", City = "Big Apple", State = "NY", Zip = "12345" } }; SendMessage(sender, "Person", student); //Send message with an object of a derived class as the body var teacher = new Teacher() { Department = "Computer Science", Classes = new List <string>() { "CS101", "CS106", "CS210" } }; SendMessage(sender, "Person", teacher); //Send message with nested simple map as the body var address = new InternationalAddress() { Address = new MapAddress() { Street = "123 Main St.", City = "Big Apple", State = "NY", Zip = "12345" }, Country = "usa" }; SendMessage(sender, "InternationalAddress", address); //Send message with an AMQP value (the described list form of a student) as the body var described = new DescribedValue( new Symbol("samples.amqpnetlite:student"), new List() { 80, 6, "black", 4.9, new DescribedValue( new Symbol("PeerToPeer.CustomType.ListAddress"), new List() { "123 Main St.", "Big Apple", "NY", "12345" } ) } ); SendMessage(sender, "Person", described); //Send message with an AMQP value (simple map of an InternationalAddress) as the body var map = new Map() { { "street", "123 Main St." }, { "city", "Big Apple" }, { "state", "NY" }, { "zip", "12345" } }; SendMessage(sender, "MapAddress", map); //Send message with an AMQP value (simple map of an InternationalAddress) as the body var map2 = new Map() { { "address", new Map() { { "street", "123 Main St." }, { "city", "Big Apple" }, { "state", "NY" }, { "zip", "12345" } } }, { "country", "usa" } }; SendMessage(sender, "InternationalAddress", map2); sender.Close(); session.Close(); connection.Close(); host.Close(); }
static void Main(string[] args) { //Create host and register message processor var uri = new Uri(Address); var host = new ContainerHost(new List<Uri>() { uri }, null, uri.UserInfo); host.RegisterMessageProcessor(MsgProcName, new MessageProcessor()); host.Open(); //Create client var connection = new Connection(new Address(Address)); var session = new Session(connection); var sender = new SenderLink(session, "message-client", MsgProcName); //Send message with an object of the base class as the body var person = new Person() { EyeColor = "brown", Height = 175, Weight = 75 }; SendMessage(sender, "Person", person); //Send message with an object of a derived class as the body var student = new Student() { GPA = 4.8, Address = new ListAddress() { Street = "123 Main St.", City = "Big Apple", State = "NY", Zip = "12345" } }; SendMessage(sender, "Person", student); //Send message with an object of a derived class as the body var teacher = new Teacher() { Department = "Computer Science", Classes = new List<string>() { "CS101", "CS106", "CS210" } }; SendMessage(sender, "Person", teacher); //Send message with nested simple map as the body var address = new InternationalAddress() { Address = new MapAddress() { Street = "123 Main St.", City = "Big Apple", State = "NY", Zip = "12345" }, Country = "usa" }; SendMessage(sender, "InternationalAddress", address); //Send message with an AMQP value (the described list form of a student) as the body var described = new DescribedValue( new Symbol("samples.amqpnetlite:student"), new List() { 80, 6, "black", 4.9, new DescribedValue( new Symbol("PeerToPeer.CustomType.ListAddress"), new List() { "123 Main St.", "Big Apple", "NY", "12345" } ) } ); SendMessage(sender, "Person", described); //Send message with an AMQP value (simple map of an InternationalAddress) as the body var map = new Map() { { "street", "123 Main St." }, { "city", "Big Apple" }, { "state", "NY" }, { "zip", "12345" } }; SendMessage(sender, "MapAddress", map); //Send message with an AMQP value (simple map of an InternationalAddress) as the body var map2 = new Map() { { "address", new Map() { { "street", "123 Main St." }, { "city", "Big Apple" }, { "state", "NY" }, { "zip", "12345" } } }, { "country", "usa" } }; SendMessage(sender, "InternationalAddress", map2); sender.Close(); session.Close(); connection.Close(); host.Close(); }
public void ContainerHostCloseTest() { string name = "ContainerHostCloseTest"; Uri uri = new Uri("amqp://*****:*****@localhost:15673"); ContainerHost h = new ContainerHost(new List <Uri>() { uri }, null, uri.UserInfo); h.Open(); h.RegisterMessageProcessor(name, new TestMessageProcessor()); //Create a client to send data to the host message processor var closedEvent = new ManualResetEvent(false); var connection = new Connection(new Address(uri.AbsoluteUri)); connection.Closed += (AmqpObject obj, Error error) => { closedEvent.Set(); }; var session = new Session(connection); var sender = new SenderLink(session, "sender-link", name); //Send one message while the host is open sender.Send(new Message("Hello"), SendTimeout); //Close the host. this should close existing connections h.Close(); Assert.IsTrue(closedEvent.WaitOne(10000), "connection is not closed after host is closed."); try { sender.Send(new Message("test")); Assert.IsTrue(false, "exception not thrown"); } catch (AmqpException exception) { Assert.IsTrue(exception.Error != null, "Error is null"); Assert.AreEqual((Symbol)ErrorCode.ConnectionForced, exception.Error.Condition, "Wrong error code"); } connection.Close(); // Reopen the host and send again // Use a different port as on some system the port is not released immediately uri = new Uri("amqp://*****:*****@localhost:15674"); h = new ContainerHost(new List <Uri>() { uri }, null, uri.UserInfo); h.RegisterMessageProcessor(name, new TestMessageProcessor()); h.Open(); connection = new Connection(new Address(uri.AbsoluteUri)); session = new Session(connection); sender = new SenderLink(session, "sender-link", name); sender.Send(new Message("Hello"), SendTimeout); connection.Close(); h.Close(); }
public void ContainerHostCloseTest() { string name = "ContainerHostCloseTest"; Uri uri = new Uri("amqp://*****:*****@localhost:15673"); ContainerHost h = new ContainerHost(new List<Uri>() { uri }, null, uri.UserInfo); h.Open(); h.RegisterMessageProcessor(name, new TestMessageProcessor()); //Create a client to send data to the host message processor var closedEvent = new ManualResetEvent(false); var connection = new Connection(new Address(uri.AbsoluteUri)); connection.Closed += (AmqpObject obj, Error error) => { closedEvent.Set(); }; var session = new Session(connection); var sender = new SenderLink(session, "sender-link", name); //Send one message while the host is open sender.Send(new Message("Hello"), SendTimeout); //Close the host. this should close existing connections h.Close(); Assert.IsTrue(closedEvent.WaitOne(10000), "connection is not closed after host is closed."); try { sender.Send(new Message("test")); Assert.IsTrue(false, "exception not thrown"); } catch (AmqpException exception) { Assert.IsTrue(exception.Error != null, "Error is null"); Assert.AreEqual((Symbol)ErrorCode.ConnectionForced, exception.Error.Condition, "Wrong error code"); } connection.Close(); // Reopen the host and send again // Use a different port as on some system the port is not released immediately uri = new Uri("amqp://*****:*****@localhost:15674"); h = new ContainerHost(new List<Uri>() { uri }, null, uri.UserInfo); h.RegisterMessageProcessor(name, new TestMessageProcessor()); h.Open(); connection = new Connection(new Address(uri.AbsoluteUri)); session = new Session(connection); sender = new SenderLink(session, "sender-link", name); sender.Send(new Message("Hello"), SendTimeout); connection.Close(); h.Close(); }