Skip to content

Nothing is received #2225

@rwb196884

Description

@rwb196884

I connect to my broker and subscribe to a topic where there is a retained message.

I expect to receive the message immediately.

But nothing happens.

        public async Task<string> Get(string topic)
        {
            using (IMqttClient mqttClient = _MqttClientFactory.CreateMqttClient())
            {
                MqttClientOptions mqttClientOptions = new MqttClientOptionsBuilder().WithTcpServer(_Options.Host).Build();
                MqttClientConnectResult rc = await mqttClient.ConnectAsync(mqttClientOptions);
                mqttClient.ApplicationMessageReceivedAsync += MqttClient_ApplicationMessageReceivedAsync;

                MqttClientSubscribeOptions mqttSubscribeOptions = _MqttClientFactory.CreateSubscribeOptionsBuilder()
                    .WithTopicFilter("zigbee2mqtt/Home/Hall/Thermostat")
                    .Build();
                MqttClientSubscribeResult rs = await mqttClient.SubscribeAsync(mqttSubscribeOptions);
                await Task.Delay(80000);
            }
            return string.Empty;
        }

        private async Task MqttClient_ApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs arg)
        {
            _Logger.LogDebug(arg.ToString());
            string payload = Encoding.UTF8.GetString(arg.ApplicationMessage.Payload);
            await Task.CompletedTask;
        }

How do I get the message and return it to the caller?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions