내 마음대로 공간

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RabbitMQ.Client;

namespace RabbitMQSend
{
    public partial class Form1 : Form
    {
        string message;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "hello2",
                                     durable: false,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: null);

                message = textBox1.Text;
                var body = Encoding.UTF8.GetBytes(message);

                channel.BasicPublish(exchange: "",
                                     routingKey: "hello2",
                                     basicProperties: null,
                                     body: body);
                //Console.WriteLine(" [x] Sent {0}", message);
            }
            label1.Text = message + "전송 완료";
            //Console.WriteLine(" Press [enter] to exit.");
            //Console.ReadLine();
        }
    }
}

RabbitMQSend.zip
3.81MB

728x90

'프로그래밍 > C#' 카테고리의 다른 글

RabbitMQ Rcv Sample Code  (0) 2021.04.02
날짜 시간 비교 및 연산 코드  (0) 2021.02.26
[C#] IP 확인하기 샘플 코드  (0) 2021.01.28

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading