Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to solve the problem of repeated message in the combination of amqpendpoint class and rabbitmq #136

Open
cmyzy opened this issue Jul 6, 2021 · 0 comments

Comments

@cmyzy
Copy link

cmyzy commented Jul 6, 2021

Hi,

I use amqpendpoint class and rabbitmq to send and consume messages, and can already send and consume messages. But there is a problem. When I send more than two messages in a loop, I can see a duplicate message in the queue of rabbitmq, that is, one of the messages has been sent many times. This does not happen when I send a message in the way of rabbirmq, but when I send a message in the way of amqpendpoint, there will be repeated messages. What is the reason?How to solve it?

Here is the code:

//Send multiple message data circularly
foreach (JObject data in toSend)
this.Kernel.Send(data);//Call the send method below

AmqpCFXEndpoint endpoint;
public void Send(string data)
{
//Sending messages using amqpendpoint class
KillEndpoint();
Uri uri = new Uri($"amqp://{this.user}:{this.password}@{this.serverIP}:{this.serverPort}");
string exchangeAddress = $"/exchange/{this.exchangeName}";

        endpoint = new AmqpCFXEndpoint();
        endpoint.HeartbeatFrequency = TimeSpan.FromMinutes(0);
        endpoint.Open("Slus.Mode.Axies");
        endpoint.AddPublishChannel(uri, exchangeAddress);

        Exception ex = null;

        if (!endpoint.TestPublishChannel(uri, exchangeAddress, out ex))
        {
            Console.WriteLine($"ERROR:  Unable to connect to broker {uri} Exchange {exchangeAddress}\nERROR MESSAGE:  {ex.Message}");
            endpoint.Close();
            return;
        }
        endpoint.Publish(CFXEnvelope.FromJson(data));
    }

private void KillEndpoint()
{
if (endpoint != null)
{
endpoint.Close();
endpoint = null;
}
}

Another point is that when messages are not sent in a loop, that is, when messages are sent one by one, there will be no duplicate messages in the queue of rabbitmq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant