- Sender: .NET 8
- Receiver: Node.js
- Protocol: AMQPS (secured AMQP)
- RabbitMQ Host:: AWS (AMQ)
- .NET: 8
- RabbitMQ Client: 6.8.1
- Node.js: 20.17.0
- amqplib: 0.10.7
| const amqplib = require('amqplib/callback_api'); | |
| const url = "amqps://<username>:<password>@<same-amq-uri-as-sender>"; | |
| const queueName = "<same-queue-name-as-sender>; | |
| console.log('Listening...'); | |
| amqplib.connect(url, (err, conn) => { | |
| if (err) throw err; | |
| conn.createChannel((err, ch2) => { | |
| if (err) throw err; | |
| ch2.assertQueue(queueName); | |
| // receives messages from the sender | |
| ch2.consume(queueName, (msg) => { | |
| if (msg !== null) { | |
| console.log(msg.content.toString()); | |
| ch2.ack(msg); | |
| } else { | |
| console.log('Consumer cancelled by server'); | |
| } | |
| }); | |
| }); | |
| }); |
| using System.Text; | |
| using System.Text.Json; | |
| namespace RabbitMQ_CSharp | |
| { | |
| internal class Program | |
| { | |
| const string AMQP_URL = "amqps://<username>:<password>@<your-amq-uri>"; | |
| static async Task Main(string[] args) | |
| { | |
| const string queueName = "<any-queue-name>"; | |
| Console.Clear(); | |
| var connectionFactory = new RabbitMQ.Client.ConnectionFactory() | |
| { | |
| Uri = new Uri(AMQP_URL), | |
| AutomaticRecoveryEnabled = true | |
| }; | |
| Console.WriteLine("Started!"); | |
| var connection = connectionFactory.CreateConnection(); | |
| var channel = connection.CreateModel(); | |
| var g = new Game { Id = 1, Name = "Splinter Cell" }; | |
| var serialized = JsonSerializer.Serialize(g); | |
| byte[] bytes = Encoding.UTF8.GetBytes(serialized); | |
| channel.QueueDeclare(queueName, | |
| durable: true, | |
| exclusive: false, | |
| autoDelete: false, | |
| arguments: null); | |
| // publishes messages to the queue | |
| channel.BasicPublish(string.Empty, queueName, false, null, bytes); | |
| Console.WriteLine("Sent!"); | |
| } | |
| } | |
| class Game | |
| { | |
| public int Id { get; set; } | |
| public string Name { get; set; } | |
| } | |
| } |