public void unrecognized_key_value() { Should.Throw <ArgumentOutOfRangeException>(() => { var endpoint = new RabbitMqEndpoint(theUri, "port=5673;host=server3;unknown=four"); }); }
public void parse_durable_uri_with_only_queue() { var endpoint = new RabbitMqEndpoint(); endpoint.Parse(new Uri("rabbitmq://queue/q1/durable")); endpoint.Mode.ShouldBe(EndpointMode.Durable); endpoint.QueueName.ShouldBe("q1"); }
public void parse_durable_uri() { var endpoint = new RabbitMqEndpoint(); endpoint.Parse(new Uri("rabbitmq://exchange/exchange1/routing/key1/durable")); endpoint.Mode.ShouldBe(EndpointMode.Durable); endpoint.ExchangeName.ShouldBe("exchange1"); endpoint.RoutingKey.ShouldBe("key1"); }
public void parse_non_durable_uri() { var endpoint = new RabbitMqEndpoint(); endpoint.Parse(new Uri("rabbitmq://exchange/exchange1/routing/key1")); endpoint.IsDurable.ShouldBeFalse(); endpoint.ExchangeName.ShouldBe("exchange1"); endpoint.RoutingKey.ShouldBe("key1"); }
private RabbitMqEndpoint InitializeRabbitMqEndpoint(ServiceProvider serviceProvider) { var endpoint = new RabbitMqEndpoint( serviceProvider, serviceProvider.GetRequiredService <ILogFactory>(), new Uri(_rabbitMqSettings.GetConnectionString()), _rabbitMqSettings.Vhost); endpoint.Initialize(); endpoint.DeclareExchange(ExchangeName); return(endpoint); }
public void EndpointReceive() { var addr = new EndpointAddress(_address); IMessageSerializer ser = new XmlMessageSerializer(); var e = new RabbitMqEndpoint(addr, ser, new RabbitMqTransport(addr, _factory.CreateConnection(_rabbitAddress)), null); e.Receive(o => { return(b => { var bb = (BugsBunny)b; Console.WriteLine(bb.Food); }); }); }
internal IncomingRabbitMqMessageEventArgs(bool isRpc, bool requiresAck, BasicDeliverEventArgs ea) { CorrelationId = new Guid(ea.BasicProperties.CorrelationId); Message = ea.Body.ToArray(); IsRpc = isRpc; RequiresAck = requiresAck; MessageSentUtc = RabbitMqEndpoint.TimestampNowUtc(ea.BasicProperties.Timestamp); MessageReceivedUtc = DateTime.UtcNow; ContentType = ea.BasicProperties.ContentType; ContentEncoding = ea.BasicProperties.ContentEncoding; Headers = ea.BasicProperties.Headers; SourceExchange = ea.Exchange; Redelivered = ea.Redelivered; SourceRoutingKeyOrTopicName = ea.RoutingKey; DeliveryTag = ea.DeliveryTag; ConsumerTag = ea.ConsumerTag; MessageId = ea.BasicProperties.MessageId; MessageType = ea.BasicProperties.Type; }
public void EndpointSend() { var addr = new EndpointAddress(_address); IMessageSerializer ser = new XmlMessageSerializer(); var msg = new BugsBunny() { Food = "Carrot" }; using (var stream = new MemoryStream()) { ser.Serialize(stream, msg); } var e = new RabbitMqEndpoint(addr, ser, new RabbitMqTransport(addr, _factory.CreateConnection(_rabbitAddress)), null); e.Send(new BugsBunny() { Food = "Carrot" }); }
static async void OnIncomingMessage(object sender, IncomingRabbitMqMessageEventArgs ea) { Console.WriteLine($"------> In the event Message='{RabbitMqEndpoint.ConvertMessageToString(ea.Message)}' sent='{ea.MessageSentUtc.ToLocalTime()}'"); var message = RabbitMqEndpoint.ConvertMessageToString(ea.Message); if (ea.RequiresAck) { Console.WriteLine("------> Sending a basic Ack"); await((RabbitMqEndpoint)sender).SendAck(ea.DeliveryTag); } if (ea.IsRpc) { var reply = "Dunno what to say..."; if (message.StartsWith("My name is ")) { var name = message.Replace("My name is ", ""); reply = $"Hello to you, {name}!"; } var me1 = (RabbitMqEndpoint)sender; await me1.ReplyAsync <string>(reply, null); } }
public void read_port() { var endpoint = new RabbitMqEndpoint(theUri, "host=server1;port=5673"); endpoint.Port.ShouldBe(5673); }
public void default_protocol_is_the_default_protocol() { var endpoint = new RabbitMqEndpoint(); endpoint.Protocol.ShouldBeOfType <DefaultRabbitMqProtocol>(); }
public void read_exchange_type() { var endpoint = new RabbitMqEndpoint(theUri, "host=server1;ExchangeType=Fanout"); endpoint.ExchangeType.ShouldBe(ExchangeType.Fanout); }
public void default_exchange_type_is_direct() { var endpoint = new RabbitMqEndpoint(theUri, "host=server1"); endpoint.ExchangeType.ShouldBe(ExchangeType.Direct); }
public void default_is_durable_is_false() { var endpoint = new RabbitMqEndpoint(theUri, "host=server1"); endpoint.TransportUri.Durable.ShouldBeFalse(); }
public void default_envelope_mapping() { var endpoint = new RabbitMqEndpoint(theUri, "host=server1"); endpoint.Protocol.ShouldBeOfType <DefaultRabbitMqProtocol>(); }
public void read_exchange() { var endpoint = new RabbitMqEndpoint(theUri, "host=server1;port=5673;ExchangeName=bar"); endpoint.ExchangeName.ShouldBe("bar"); }
public void default_port_is_5672() { var endpoint = new RabbitMqEndpoint(theUri, "host=server1"); endpoint.Port.ShouldBe(5672); }
public void read_host_from_connection_string() { var endpoint = new RabbitMqEndpoint(theUri, "host=server1;"); endpoint.Host.ShouldBe("server1"); }
static async Task Main(string[] args) { var mp = new MessageParameters() { AutoAck = false, Durable = true, Mandatory = true, Persistent = true, Priority = 3, Resilient = true, TimeOut = 32000 }; var ep = new PublisherParameters() { AutoDelete = false, Durable = true, AcceptReplies = true, ReplyQueueTtl = 8000, Ttl = 8000, EnableConfirmSelect = true }; Console.Write("Enter server name to connect to: "); var broker = Console.ReadLine(); Console.Write("Login Name: "); var login = Console.ReadLine(); Console.Write("Password: "******"/", login, password, 0, "RabbitMqFacadeTest1", cts); var cp = new ConsumerParameters() { AutoAckMode = ConsumerParameters.AutoAckModeEnum.Manual, AutoDelete = false, Durable = true }; var consumer = RabbitMqEndpoint.NewInboundConsumer("test", "d", "d", cp); consumer.IncomingMessage += OnIncomingMessage; consumer.Listen(); var publisher = RabbitMqEndpoint.NewOutboundPublisher("test", "d", "d", ep, mp); var response = await publisher.SendRpcMessageAsync("My name is Bob"); if (response == null) { Console.WriteLine("No one there!"); } else { Console.WriteLine(RabbitMqEndpoint.ConvertMessageToString(response)); } response = await publisher.SendRpcMessageAsync("My name is Sue"); if (response == null) { Console.WriteLine("No one there!"); } else { Console.WriteLine(RabbitMqEndpoint.ConvertMessageToString(response)); } response = await publisher.SendRpcMessageAsync("Ribbit"); if (response == null) { Console.WriteLine("No one there!"); } else { Console.WriteLine(RabbitMqEndpoint.ConvertMessageToString(response)); } response = await publisher.SendRpcMessageAsync("My name is Rachel"); if (response == null) { Console.WriteLine("No one there!"); } else { Console.WriteLine(RabbitMqEndpoint.ConvertMessageToString(response)); } Console.ReadLine(); }