public void TestSendAndReceiveWithFanout() { var admin = new RabbitAdmin(this.connectionFactory); var exchange = new FanoutExchange("fanout"); admin.DeclareExchange(exchange); this.template.Exchange = exchange.Name; admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange)); this.template.Execute <object>( delegate { var consumer = this.CreateConsumer(this.template); var tag = consumer.ConsumerTag; Assert.IsNotNull(tag); try { this.template.ConvertAndSend("message"); var result = this.GetResult(consumer); Assert.AreEqual("message", result); } finally { consumer.Stop(); } return(null); }); }
static void Main(string[] args) { var factory = new ConnectionFactory() { HostName = "localhost", UserName = "******", Password = "******" }; using var connection = factory.CreateConnection(); using var channel = connection.CreateModel(); FanoutExchange.Publish(channel); }
static void Main(string[] args) { var factory = new ConnectionFactory() { HostName = "localhost", UserName = "******", Password = "******" }; var connection = factory.CreateConnection(); var channel = connection.CreateModel(); FanoutExchange.Receive(channel); Console.ReadLine(); }
static void Main(string[] args) { try { #region 架构师VIP班-2 { FanoutExchange.Show(); } #endregion Console.Read(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.Read(); }
static void Main(string[] args) { Console.WriteLine("I am a RabbitMQ Producer. Environment friendly :D "); string UserName = "******"; string Password = "******"; string HostName = "localhost"; //Main entry point to the RabbitMQ .NET AMQP client #region "Connection and Initialization" var connectionFactory = new RabbitMQ.Client.ConnectionFactory() { UserName = UserName, Password = Password, HostName = HostName }; var connection = connectionFactory.CreateConnection(); var channel = connection.CreateModel(); //Create a channel #endregion #region "Basic Demo" // BasicQueue.Publish(channel); #endregion #region "Exchange Demo" // DirectExchange.Publish(channel); #endregion #region "Topic Demo" //TopicExchange.Publish(channel); #endregion #region "Header Demo" // HeaderExchange.Publish(channel); #endregion #region "Fanout Demo" FanoutExchange.Publish(channel); #endregion Console.ReadKey(); }
public void TestSendAndReceiveWithFanout() { provider = services.BuildServiceProvider(); var admin = provider.GetRabbitAdmin(); var exchange = new FanoutExchange("fanout"); admin.DeclareExchange(exchange); admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange)); var template = provider.GetRabbitTemplate(); template.DefaultSendDestination = new RabbitDestination(exchange.ExchangeName, string.Empty); try { template.Execute(channel => { var consumer = CreateConsumer(template.ConnectionFactory); var tag = consumer.GetConsumerTags()[0]; Assert.NotNull(tag); try { template.ConvertAndSend("message"); var result = GetResult(consumer, true); Assert.Equal("message", result); } finally { consumer.Stop(); } }); } finally { admin.DeleteExchange("fanout"); } }
/// <summary> /// 订阅模式 /// </summary> /// <param name="msg"></param> /// <returns></returns> public Task <JsonResult> SendFanoutMessage([FromBody] SendMessageDto dto) { fanoutExchange = new FanoutExchange(); fanoutExchange.SendMQ(dto.Message); return(Task.FromResult(Json(true))); }