Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("开始往集群中发布消息...");
            using (var rabbitmqProxy = new RabbitMQWrapper())
            {
                for (int i = 0; i < Int32.MaxValue; i++)
                {
                    try
                    {
                        var debugLog = new DebugLog
                        {
                            Id          = i,
                            CreatedTime = DateTime.Now
                        };

                        rabbitmqProxy.Publish(debugLog);
                        Console.WriteLine(string.Format("{0} OK", i));

                        System.Threading.Thread.Sleep(1 * 1000);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     using (var wrapper = new RabbitMQWrapper())
     {
         wrapper.Consume("Books", GetQueueHandler("Books"));
         wrapper.Consume("Authors", GetQueueHandler("Authors"));
         Console.WriteLine("Press enter to quit.");
         Console.ReadLine();
     }
 }
Beispiel #3
0
        static public void TestQWrapper()
        {
#if false
            RabbitMQWrapper pubQueue = new RabbitMQWrapper("AnalysisFarm", "AnalysisRequest", "localhost");

            while (!Console.KeyAvailable)
            {
                if (pubQueue.QueueEmpty())
                {
                    pubQueue.PostTestMessages();
                }
            }
            pubQueue.CloseConnections();
#endif
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            for (int i = 1; i < 5; i++)
            {
                UserInfo userinfo = new UserInfo {
                    UserName = "******" + i.ToString(), Password = "******"
                };
                RabbitMQWrapper.Publish(userinfo);
            }

            RabbitMQWrapper.Subscribe <UserInfo>(x =>
            {
                System.Console.WriteLine(x.UserName);
            });

            System.Console.ReadLine();
        }
Beispiel #5
0
        private void OnTimer(object sender, ElapsedEventArgs args)
        {
            using (var wrapper = new RabbitMQWrapper())
            {
                using (var authorRepo = new AuthorRepo())
                {
                    var authors  = authorRepo.GetALL();
                    var json     = JsonConvert.SerializeObject(authors);
                    var byteData = Encoding.UTF8.GetBytes(json);
                    wrapper.SendMessage(ConfigurationManager.AppSettings["RabbitMQExchange"], "Author", byteData);
                }

                using (var bookRepo = new BookRepo())
                {
                    var books    = bookRepo.GetALL();
                    var json     = JsonConvert.SerializeObject(books);
                    var byteData = Encoding.UTF8.GetBytes(json);
                    wrapper.SendMessage(ConfigurationManager.AppSettings["RabbitMQExchange"], "Book", byteData);
                }
            }
        }
Beispiel #6
0
        public MainService()
        {
            tasks       = new List <Task>();
            cancelToken = new CancellationTokenSource();

            //Autofac初始化
            container = LogNewHelper.BuildAutofacContainer();

            //rabbitMQ初始化
            var config = System.Configuration.ConfigurationManager.GetSection("rabbitMQ") as RabbitMQConfigurationSection;

            rabbitMQProxy = new RabbitMQWrapper(new RabbitMQConfig
            {
                Host        = config.HostName,
                VirtualHost = config.VHost,
                HeartBeat   = 60,
                AutomaticRecoveryEnabled = true,
                UserName = config.UserName,
                Password = config.Password
            });
        }
Beispiel #7
0
 public MainService()
 {
     //rabbitmq初始化
     rabbitmqProxy = new RabbitMQWrapper();
 }
Beispiel #8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     RabbitMQWrapper.Publish(new Object());
 }