2

コンシューマー内で RabbitMQ からメッセージを受信して​​います。そのメッセージを処理し、処理されたメッセージを別のキューに発行する必要があります。どうすればこれを達成できますか?

私のコードは

using (IConnection connection = factory.CreateConnection())
{
    using (IModel channel = connection.CreateModel())
    {
        if (!String.IsNullOrEmpty(EXCHANGE_NAME))
            channel.ExchangeDeclare(EXCHANGE_NAME, ExchangeType.Direct, durable);

        if (!String.IsNullOrEmpty(QUEUE_NAME))
            channel.QueueDeclare(QUEUE_NAME, false, false, false, null);

        string data = "";
        EventingBasicConsumer consumer = new EventingBasicConsumer();
        consumer.Received += (o, e) =>
        {
            //This is the received message
            data = data + Encoding.ASCII.GetString(e.Body) + Environment.NewLine;
            string processed_data = "processed data = " + data; 
            //I want to write some code here to post the processed message to a different queue.
            //or other idea is "can I use duplex services? 

        };
        string consumerTag = channel.BasicConsume(QUEUE_NAME, true, consumer);

        channel.QueueBind(QUEUE_NAME, EXCHANGE_NAME, ROUTING_KEY, null);
        channel.QueueUnbind(QUEUE_NAME, EXCHANGE_NAME, ROUTING_KEY, null);
    }
}
4

1 に答える 1