Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using RabbitMQ.Client;
- using System.Text;
- namespace Send {
- public static class IModelExtensions {
- public static void Publish(this IModel channel, string msg) {
- byte [] body = Encoding.UTF8.GetBytes(msg);
- channel.BasicPublish("", "hello", null, body);
- }
- }
- class Send {
- static ConnectionFactory CreateConnection() => new ConnectionFactory() {
- HostName = "192.168.15.40",
- UserName = "rfid",
- Password = "rfid"
- };
- static void Main(string[] args) {
- Console.WriteLine("Press any key to start: ");
- Console.ReadKey();
- var factory = CreateConnection();
- using(IConnection connection = factory.CreateConnection()) {
- using(IModel channel = connection.CreateModel()) {
- channel.QueueDeclare(
- queue: "hello",
- durable: false,
- exclusive: false,
- autoDelete: false,
- arguments: null
- );
- for(int i = 0; i < 100; i++) {
- string msg = Guid.NewGuid().ToString();
- channel.Publish(msg);
- Console.WriteLine($"[-] Sent {i+1} {msg}");
- }
- }
- }
- Console.WriteLine("Press [Enter] to exit.");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement