public void EndpointSendAndReceive()
        {
            using (var management = new RabbitMqEndpointManagement(_queue))
            {
                management.BindQueue(_queue.Name, _exchange.Name, ExchangeType.Fanout, "", null);
            }

            IMessageSerializer serializer = new XmlMessageSerializer();

            var message = new BugsBunny {Food = "Carrot"};

            IDuplexTransport transport = _factory.BuildLoopback(new TransportSettings(_exchange));
            IOutboundTransport error = _factory.BuildError(new TransportSettings(_error));

            var sendEndpoint = new Endpoint(_exchange, serializer, transport, error,
                new InMemoryInboundMessageTracker(5));
            sendEndpoint.Send(message);


            var receiveEndpoint = new Endpoint(_queue, serializer, transport, error,
                new InMemoryInboundMessageTracker(5));
            receiveEndpoint.Receive(o =>
                {
                    return b =>
                        {
                            var bb = (BugsBunny)b;
                            Console.WriteLine(bb.Food);
                        };
                }, TimeSpan.Zero);
        }
        public void TransportSendAndReceive()
        {
            using (var management = new RabbitMqEndpointManagement(_queue))
            {
                management.BindQueue(_queue.Name, _exchange.Name, ExchangeType.Fanout, "", null);
            }

            IOutboundTransport t = _factory.BuildOutbound(new TransportSettings(_exchange));
            var context = new SendContext<string>("dru");
            context.SetBodyWriter(stream =>
                {
                    byte[] buffer = Encoding.UTF8.GetBytes(context.Message);
                    stream.Write(buffer, 0, buffer.Length);
                });
            t.Send(context);

            IInboundTransport i = _factory.BuildInbound(new TransportSettings(_queue));

            i.Receive(s =>
                {
                    return ss =>
                        {
                            string name;
                            using (var stream = new MemoryStream())
                            {
                                ss.CopyBodyTo(stream);

                                name = Encoding.UTF8.GetString(stream.ToArray());
                            }

                            Assert.AreEqual("dru", name);
                            Console.WriteLine(name);
                        };
                }, 1.Minutes());
        }
        public void OnSubscriptionRemoved(SubscriptionRemoved message)
        {
            Guard.AgainstNull(_inputAddress, "InputAddress", "The input address was not set");

            MessageName messageName;
            if (_bindings.TryGetValue(message.SubscriptionId, out messageName))
            {
                using (var management = new RabbitMqEndpointManagement(_inputAddress))
                {
                    management.UnbindExchange(_inputAddress.Name, messageName.ToString(), "");
                }

                _bindings.Remove(message.SubscriptionId);
            }
        }
        public void OnSubscriptionAdded(SubscriptionAdded message)
        {
            Guard.AgainstNull(_inputAddress, "InputAddress", "The input address was not set");

            Type messageType = Type.GetType(message.MessageName);
            if (messageType == null)
            {
                _log.InfoFormat("Unknown message type '{0}', unable to add subscription", message.MessageName);
                return;
            }

            MessageName messageName = _messageNameFormatter.GetMessageName(messageType);

            using (var management = new RabbitMqEndpointManagement(_inputAddress))
            {
                management.BindExchange(_inputAddress.Name, messageName.ToString(), ExchangeType.Fanout, "");
            }

            _bindings[message.SubscriptionId] = messageName;
        }
		void DeclareBindings()
		{
			if (_declared)
				return;

			using (var management = new RabbitMqEndpointManagement(_address, _connection))
			{
				management.BindQueue(_address.Name, _address.Name, ExchangeType.Fanout, "");
			}

			_declared = true;
		}
		static void BindErrorExchangeToQueue(IRabbitMqEndpointAddress address, IConnection connection)
		{
			// we need to go ahead and bind a durable queue for the error transport, since
			// there is probably not a listener for it.

			using (var management = new RabbitMqEndpointManagement(address, connection))
			{
				management.BindQueue(address.Name, address.Name, ExchangeType.Fanout, "");
			}
		}
		static void PurgeExistingMessages(ConnectionHandler<RabbitMqConnection> connectionHandler,
		                                  IRabbitMqEndpointAddress address)
		{
			connectionHandler.Use(connection =>
				{
					using (var management = new RabbitMqEndpointManagement(address, connection.Connection))
					{
						management.Purge(address.Name);
					}
				});
		}