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;
using RabbitMQ.Client.Events;
namespace RabbitMQRcv
{
public partial class Form1 : Form
{
string rst1;
public Form1()
{
InitializeComponent();
timer1.Start();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(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);
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body.ToArray();
var message = Encoding.UTF8.GetString(body);
rst1 = message;
};
channel.BasicConsume(queue: "hello2",
autoAck: true,
consumer: consumer);
//Console.WriteLine(" Press [enter] to exit.");
//Console.ReadLine();
}
textBox1.Text = rst1;
label1.Text = rst1 + "전송완료";
}
}
}