


Detailed explanation of graphic code for RabbitMQ application in C#
rabbitmq is not described as and how to install it. Baidu knows it at once, just pay more attention in terms of configuration.
Without further ado, let’s start with a simple example code
Sender:
ConnectionFactory factory = new ConnectionFactory { HostName = "hostname", UserName = "root", Password = "root001", VirtualHost = "hostserver" }; using (IConnection conn = factory.CreateConnection()) { using (IModel im = conn.CreateModel()) { im.ExchangeDeclare("rabbitmq_route", ExchangeType.Direct); im.QueueDeclare("rabbitmq_query", false, false, false, null); im.QueueBind("rabbitmq_query", "rabbitmq_route", ExchangeType.Direct, null); for (int i = 0; i < 1000; i++) { byte[] message = Encoding.UTF8.GetBytes("Hello Lv"); im.BasicPublish("rabbitmq_route", ExchangeType.Direct, null, message); Console.WriteLine("send:" + i); } } }
Receiver:
ConnectionFactory factory = new ConnectionFactory { HostName = "hostname", UserName = "root", Password = "root001", VirtualHost = "hostserver" }; using (IConnection conn = factory.CreateConnection()) { using (IModel im = conn.CreateModel()) { while (true) { BasicGetResult res = im.BasicGet("rabbitmq_query", true); if (res != null) { Console.WriteLine("receiver:"+UTF8Encoding.UTF8.GetString(res.Body)); } } } }
Send a thousand sending one at one time, the sending process is fast, and it is relatively slow when receiving.
Just end it.
It can be seen that when two receivers are running at the same time, RabbitMQ will Distribute each message sequentially. When each confirmation is received, the message will be deleted, and then the next one will be distributed to the next recipient, mainly because of RabbitMQ's
cyclic distribution mechanism.
Modify the sending terminal code:
##
ConnectionFactory factory = new ConnectionFactory { HostName = "hostname", UserName = "root", Password = "root001", VirtualHost = "host" }; using (IConnection conn = factory.CreateConnection()) { using (IModel im = conn.CreateModel()) { im.ExchangeDeclare("rabbitmq_route_Fanout", ExchangeType.Fanout);// 路由 int i = 0; while (true) { Thread.Sleep(1000); ++i; byte[] message = Encoding.UTF8.GetBytes(i.ToString()); im.BasicPublish("rabbitmq_route_Fanout", "", null, message); Console.WriteLine("send:" + i.ToString()); } } }
# When a new receiving end connection (consumer), you need to declare a new queue, Comment on code 1. When RabbitMQ declares a queue, it will automatically generate one if you do not specify a name, which is good.
What are the disadvantages? You will know after running it yourself.
The above is the detailed content of Detailed explanation of graphic code for RabbitMQ application in C#. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to build a reliable messaging application with React and RabbitMQ Introduction: Modern applications need to support reliable messaging to achieve features such as real-time updates and data synchronization. React is a popular JavaScript library for building user interfaces, while RabbitMQ is a reliable messaging middleware. This article will introduce how to combine React and RabbitMQ to build a reliable messaging application, and provide specific code examples. RabbitMQ overview:

How to use RabbitMQ to implement distributed message processing in PHP Introduction: In large-scale application development, distributed systems have become a common requirement. Distributed message processing is a pattern that improves the efficiency and reliability of the system by distributing tasks to multiple processing nodes. RabbitMQ is an open source, reliable message queuing system that uses the AMQP protocol to implement message delivery and processing. In this article we will cover how to use RabbitMQ in PHP for distribution

How to ensure that messages are not lost. The rabbitmq message delivery path producer->switch->queue->consumer is generally divided into three stages. 1. The producer ensures the reliability of message delivery. 2.MQ internal messages are not lost. 3. Consumer consumption is successful. What is message delivery reliability? Simply put, it means that messages are 100% sent to the message queue. We can turn on confirmCallback. After the producer delivers the message, mq will give the producer an ack. Based on the ack, the producer can confirm whether the message is sent to mq. Turn on confirmCallback and modify the configuration file #NONE: disable the release confirmation mode, which is the default value , CORRELATED:

As modern applications increase in complexity, messaging has become a powerful tool. In this area, RabbitMQ has become a very popular message broker that can be used to deliver messages between different applications. In this article, we will explore how to use RabbitMQ in Go language. This guide will cover the following: Introduction to RabbitMQ RabbitMQ Installation RabbitMQ Basic Concepts Getting Started with RabbitMQ in Go RabbitMQ and Go

Whether you are a beginner or an experienced professional, mastering C# will pave the way for your career.

Introduction to the solution for real-time data synchronization between Golang and RabbitMQ: In today's era, with the popularity of the Internet and the explosive growth of data volume, real-time data synchronization has become more and more important. In order to solve the problems of asynchronous data transmission and data synchronization, many companies have begun to use message queues to achieve real-time synchronization of data. This article will introduce a real-time data synchronization solution based on Golang and RabbitMQ, and provide specific code examples. 1. What is RabbitMQ? Rabbi

The development of artificial intelligence (AI) technologies is in full swing today, and they have shown great potential and influence in various fields. Today Dayao will share with you 4 .NET open source AI model LLM related project frameworks, hoping to provide you with some reference. https://github.com/YSGStudyHards/DotNetGuide/blob/main/docs/DotNet/DotNetProjectPicks.mdSemanticKernelSemanticKernel is an open source software development kit (SDK) designed to integrate large language models (LLM) such as OpenAI, Azure

Now more and more companies are beginning to adopt the microservice architecture model, and in this architecture, message queues have become an important communication method, among which RabbitMQ is widely used. In the Go language, go-zero is a framework that has emerged in recent years. It provides many practical tools and methods to allow developers to use message queues more easily. Below we will introduce go-zero based on practical applications. And the usage and application practice of RabbitMQ. 1.RabbitMQ OverviewRabbit
