Last active
January 8, 2022 10:27
-
-
Save hkucuk/e547614e766a2d852101f239e10c1a54 to your computer and use it in GitHub Desktop.
create a rabbitmq publisher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
using RabbitMQ.Client; | |
var factory = new ConnectionFactory(); | |
//AMQP URL | |
factory.Uri = new Uri("amqps://fxunuiqu:url_adres"); | |
var queueName = "test-queue"; | |
using (var connection = factory.CreateConnection()) | |
{ | |
var channel = connection.CreateModel(); | |
channel.QueueDeclare | |
( | |
queue: queueName, | |
durable: true, //true degeri kuyruk bellekte oluşturulmasın ve fiziksel olarak kaydedilsin anlamina gelir. | |
exclusive: false,//false degeri kuyruga sadece olsuturuldugu makineden degil heryerden baglanılabilsin anlamina gelir. | |
autoDelete: false //false degeri istemcilerin işi bittiğinde kuyruk otomatik olarak silinmesin anlamina gelir. | |
); | |
for (int i = 0; i < 50; i++) | |
{ | |
var data = Encoding.UTF8.GetBytes($"{i}. mesaj : {Guid.NewGuid()}"); | |
channel.BasicPublish | |
( | |
exchange: "", | |
routingKey: queueName, | |
mandatory: true, | |
basicProperties: null, | |
body: data | |
); | |
Console.WriteLine($"{i}. mesaj gönderildi."); | |
} | |
} | |
Console.WriteLine("Mesaj Gönderildi"); | |
Console.Read(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment