zoukankan      html  css  js  c++  java
  • RabbitMQ 安装配置和简单实例

    安装ErLang运行环境

    image

    配置运行环境变量

    image

    启动服务

    地址在:complete-rabbitmq-bundle-1.7.0\rabbitmq-server-windows-1.7.0\rabbitmq_server-1.7.0\sbin

    image

    image

    一段实例代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using RabbitMQ.Client;
    
    namespace rabbits
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            IConnection conn;
            IModel channel;
            private void button1_Click(object sender, EventArgs e)
            {
                conn = new ConnectionFactory().CreateConnection(Protocols.DefaultProtocol, this.textBox1.Text);
                channel = conn.CreateModel();
                channel.ExchangeDeclare(this.textBox2.Text, ExchangeType.Direct);
                channel.QueueDeclare(this.textBox3.Text);
                channel.QueueBind(this.textBox3.Text, this.textBox2.Text, "", false, null);
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                byte[] message = System.Text.Encoding.UTF8.GetBytes(this.richTextBox1.Text);
                IBasicProperties props = channel.CreateBasicProperties();
                props.ContentType = "text/plain";
                props.DeliveryMode = 2;
    
                channel.BasicPublish(this.textBox2.Text, "", props, message);
    
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                bool noask = false;
                BasicGetResult result = channel.BasicGet(this.textBox3.Text, noask);
                if (result == null)
                {
                    
                }
                else
                {
                    IBasicProperties props = result.BasicProperties;
                    byte[] body = result.Body;
                    this.richTextBox2.Text = System.Text.Encoding.UTF8.GetString(body);
                    channel.BasicAck(result.DeliveryTag, false);
                        
                }
            }
    
            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                if (this.channel != null && this.channel.IsOpen)
                {
                    this.channel.Dispose();
                }
                if (this.conn != null && this.conn.IsOpen)
                {
                    this.conn.Dispose();
                }
            }
    
            
        }
    }

    冯瑞涛
  • 相关阅读:
    web开发(六) EL表达式
    web开发(五) JSP详解(四大作用域九大内置对象等)
    web开发(四) 一次性验证码的代码实现
    Netty4
    Android Fragment
    Android 6.0 双向通话自动录音
    安卓
    SpringMVC + Spring + Mybatis+ Redis +shiro以及MyBatis学习
    Spring 3 AOP 概念及完整示例
    Java并发之CountDownLatch、CyclicBarrier和Semaphore
  • 原文地址:https://www.cnblogs.com/finehappy/p/1653466.html
Copyright © 2011-2022 走看看