using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RabbitMQ.Client;
using System.Threading;
namespace RabbitSend
{
class Program
{
private const string EXCHANGE_NAME1 = "user1";
private const string EXCHANGE_NAME2 = "user2";
public static void Main(string[] args)
{
var factory = new ConnectionFactory() { HostName = "localhost", UserName = "vhost1admin", Password = "changeme", VirtualHost = "vhost1", Protocol = Protocols.DefaultProtocol, Port = AmqpTcpEndpoint.UseDefaultPort };
using(IConnection connection = factory.CreateConnection())
{
using(IModel channel = connection.CreateModel())
{
Dictionary<string,object> dict = new Dictionary<string, object>();
dict.Add("expires", 60000);
channel.ExchangeDeclare(EXCHANGE_NAME1, "topic", false,false, dict);
channel.ExchangeDeclare(EXCHANGE_NAME2, "topic", false, false, dict);
for (int i = 0; i < 10000000; i++)
{
byte[] payload = Encoding.ASCII.GetBytes(EXCHANGE_NAME1 + ":" + i);
channel.BasicPublish(EXCHANGE_NAME1, EXCHANGE_NAME1 + ".service1.key1", null, payload);
payload = Encoding.ASCII.GetBytes(EXCHANGE_NAME2 + ":" + i);
channel.BasicPublish(EXCHANGE_NAME2, EXCHANGE_NAME1 +".service1.key1", null, payload);
Console.WriteLine("Sent Message " + i);
Thread.Sleep(1000);
}
}
}
}
}
}