码迷,mamicode.com
首页 > 其他好文 > 详细

rabbitMQ学习

时间:2017-11-09 19:42:22      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:链接   service   error   同事   from   enc   section   rabbitmq   file   

学习地址:

1、http://www.cnblogs.com/ericli-ericli/p/5902270.html

感谢大神的分析,感谢同事的指导。

2、按照要求一步步配置。

3、打开http://localhost:15672/#/

技术分享

4、创建虚拟账户

技术分享

单击:赋权限

技术分享

 

5、代码如下:下载地址:链接:http://pan.baidu.com/s/1bpKwtND 密码:el5q

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Sangmado.Inka.MomBrokers;
using Sangmado.Inka.MomBrokers.TestConsole;

namespace QMessage
{
    class Program
    {
        static void Main(string[] args)
        {
            Person per = new Person();
            per.Id = "123";
            per.Name = "hh爱学习";




            var publishingChannel = new OutgoingMomChannel(
                TestPublishingChannelConfiguration.GetHostSetting(),
                TestPublishingChannelConfiguration.GetExchangeSetting(),
                TestPublishingChannelConfiguration.GetQueueSetting(),
                TimeSpan.FromSeconds(15));

            var consumingChannel = new IncomingMomChannel(
                TestConsumingChannelConfiguration.GetHostSetting(),
                TestConsumingChannelConfiguration.GetExchangeSetting(),
                TestConsumingChannelConfiguration.GetQueueSetting(),
                TimeSpan.FromSeconds(15));


            publishingChannel.Connect();
            consumingChannel.Connect();

            publishingChannel.Publish(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(per)));

            //consumingChannel.StartConsume();



            Console.ReadLine();



        }
    }
    public class Person {
        public string Id { get; set; }

        public string Name { get; set; }
    }
}

 5、配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<appSettings>

<add key="TestPublishingChannelHostClientServiceName" value="TestConsole"/>
<add key="TestPublishingChannelHostName" value="localhost"/>
<add key="TestPublishingChannelHostPort" value="5672"/>
<add key="TestPublishingChannelHostVirtualHost" value="/prod"/>
<add key="TestPublishingChannelHostUserName" value="guest"/>
<add key="TestPublishingChannelHostPassword" value="guest"/>
<add key="TestPublishingChannelExchangeName" value="test.exchange"/>
<add key="TestPublishingChannelExchangeType" value="fanout"/>
<add key="TestPublishingChannelExchangeDurable" value="false"/>
<add key="TestPublishingChannelExchangeAutoDelete" value="false"/>
<add key="TestPublishingChannelQueueName" value=""/>
<add key="TestPublishingChannelQueueDurable" value="true"/>
<add key="TestPublishingChannelQueueExclusive" value="false"/>
<add key="TestPublishingChannelQueueAutoDelete" value="false"/>
<add key="TestPublishingChannelQueueNoAck" value="false"/>
<add key="TestPublishingChannelQueueBindRoutingKeys" value=""/>

<add key="TestConsumingChannelHostClientServiceName" value="TestConsole"/>
<add key="TestConsumingChannelHostName" value="localhost"/>
<add key="TestConsumingChannelHostPort" value="5672"/>
<add key="TestConsumingChannelHostVirtualHost" value="/prod"/>
<add key="TestConsumingChannelHostUserName" value="guest"/>
<add key="TestConsumingChannelHostPassword" value="guest"/>
<add key="TestConsumingChannelExchangeName" value="test.exchange"/>
<add key="TestConsumingChannelExchangeType" value="fanout"/>
<add key="TestConsumingChannelExchangeDurable" value="false"/>
<add key="TestConsumingChannelExchangeAutoDelete" value="false"/>
<add key="TestConsumingChannelQueueName" value="test.queue"/>
<add key="TestConsumingChannelQueueDurable" value="true"/>
<add key="TestConsumingChannelQueueExclusive" value="false"/>
<add key="TestConsumingChannelQueueAutoDelete" value="false"/>
<add key="TestConsumingChannelQueueNoAck" value="false"/>
<add key="TestConsumingChannelQueueBindRoutingKeys" value=""/>

</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
<nlog autoReload="true" throwExceptions="true">
<targets>
<target name="console" type="ColoredConsole" encoding="utf-8" layout="${longdate}|${level:uppercase=true}|${logger}|${message}" useDefaultRowHighlightingRules="true"/>
<target name="file" type="File" fileName="${basedir}/logs/test-${shortdate}.log" layout="${longdate}|${level:uppercase=true}|${logger}|${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="console"/>
<logger name="*" minlevel="Error" writeTo="file"/>
</rules>
</nlog>
</configuration>

 

rabbitMQ学习

标签:链接   service   error   同事   from   enc   section   rabbitmq   file   

原文地址:http://www.cnblogs.com/honghong75042/p/7810845.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!