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

PublishingManager #15

Open
ghost opened this issue Feb 12, 2014 · 0 comments
Open

PublishingManager #15

ghost opened this issue Feb 12, 2014 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 12, 2014

Hi, I'm using QOS ExactlyOnce. Is this supported as I notice you have an issue below. Basically when I use this the code below throws an error. It is because the GetNextMessageIdentifier returns a count only unique per topic. The id is then added to publishedMessages dictionary which contains all sent messages. Therefore I send a message to topic A and then to topic B, both will be given ID 1 and the dictionary add fails as the key already exists. Am I doing something wrong?

public short Publish(string topic, MqttQos qualityOfService, object data)
where TDataConverter : IPublishDataConverter
{
short msgID = MessageIdentifierDispenser.GetNextMessageIdentifier(String.Format("Topic:{0}", topic));

        IPublishDataConverter converter = GetPublishDataConverter<TDataConverter>();

        MqttPublishMessage msg = new MqttPublishMessage()
            .ToTopic(topic)
            .WithMessageIdentifier(msgID)
            .WithQos(qualityOfService)
            .PublishData(converter.ConvertToBytes(data));

        // QOS level 1 or 2 messages need to be saved so we can do the ack processes
        if (qualityOfService == MqttQos.AtLeastOnce || qualityOfService == MqttQos.ExactlyOnce)
        {
            Console.WriteLine("{0}",System.Threading.Thread.CurrentThread.ManagedThreadId);
            publishedMessages.Add(msgID, msg);
        }

        connectionHandler.SendMessage(msg);

        return msgID;
    }

I fixed this by adding the following unpleasant hack at the start of function MessageIdentifierDispenser.GetNextMessageIdentifier:

key = "All";

Thereby ensuring that all messages are counted consecutively regardless of topic

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

0 participants