Discarding Old Messages not working

Hello I have the following convention.

            endpointConfiguration.Conventions().DefiningTimeToBeReceivedAs(t =>
            {
                if (t == typeof(DepositMoney))
                {
                    return TimeSpan.FromSeconds(90);
                }
                else if (t == typeof(CompletePaymentRequest))
                {
                    return TimeSpan.FromSeconds(90);
                }

                return TimeSpan.MaxValue;
                //return t switch
                //{
                //    Type c when c == typeof(DepositMoney) => TimeSpan.FromSeconds(90),
                //    Type c when c == typeof(CompletePaymentRequest) => TimeSpan.FromSeconds(90),
                //    _ => TimeSpan.MaxValue
                //};
            });

I am expecting that the command does not get executed after 90 seconds.

The way I am testing is the following
Stop Endpoing
Api gateway send command to Endpoint
Wait past 90 seconds
Start Endpoint… expectation is for message to be discarded… however it does not get discard

Actually the seems to be that the config has to be in both the api gateway and microservice…

Could you provide more context? Where is your code running? What’s your setup? What are you trying to achieve?

The exact message discard behavior might depend on the transport you are using. https://docs.particular.net/nservicebus/messaging/discard-old-messages#caveats describes some of the caveats and different behaviors across the transports. Depending on the transport, it might be necessary to define the convention also on the receiving side of a message (it seems you have already noticed that and I assume this fixed the problem?).

Hi guys

yes, issue fixed. Convention has to be in both sending and receiving side