src/Messaging.cs
/// <summary>
/// Gets the next informed queue's message and deserializes it to an object.
/// Once the message is dequeued, it is deleted from the queue.
/// Depending on the service, this method may take a few seconds to return, waiting for new messages before completion.
/// If no message is found, returns null.
/// </summary>
/// <typeparam name="T">The type to which the message will be deserialized to.</typeparam>
/// <param name="config">The queue configuration.</param>
/// <exception cref="InvalidOperationException">Occurs when the connection to the server fails.</exception>
Gets the next informed queue's message and deserializes it to an object.
Once the message is dequeued, it is deleted from the queue.
Depending on the service, this method may take a few seconds to return, waiting for new messages before completion.
If no message is found, returns null.
Gets the next informed queue ' s message and deserializes it to an object . Once the message is dequeued it is deleted from the queue . Depending on the service this method may take a few seconds to return waiting for new messages before completion . If no message is found returns null .
public static T Dequeue<T>(string queueName, IMessagingConfig config)
        {
            queueName = queueName.ToLower();
            Utils.ValidateQueueName(queueName, true);
            object deserialized = null;
            Exception exToThrow = null;
            using (var client = new Messaging(config))
            {
                var transporter = client.GetTransporter(queueName);
                transporter.DequeueSingleMessage(queueName, (msg) =>
                {
                    if (msg == null)
                    {
                        deserialized = null;
                        return true;
                    }
                    try
                    {
                        deserialized = Utils.DeserializeObject<T>(msg);
                        return true;
                    }
                    catch (Exception e)
                    {
                        exToThrow = e;
                        return false;
                    }
                });
            }
            if (exToThrow != null)
                throw new InvalidCastException("Error parsing the object. Message requeued.", exToThrow);
            return (T)deserialized;
        }
public static T Dequeue < T > ( string queueName , IMessagingConfig config ) { queueName = queueName . ToLower ( ) ; Utils . ValidateQueueName ( queueName , true ) ; object deserialized = null ; Exception exToThrow = null ; using ( var client = new Messaging ( config ) ) { var transporter = client . GetTransporter ( queueName ) ; transporter . DequeueSingleMessage ( queueName , ( msg ) => { if ( msg == null ) { deserialized = null ; return true ; } try { deserialized = Utils . DeserializeObject < T > ( msg ) ; return true ; } catch ( Exception e ) { exToThrow = e ; return false ; } } ) ; } if ( exToThrow != null ) throw new InvalidCastException ( " " , exToThrow ) ; return ( T ) deserialized ; }
Gets the next informed queue's message and deserializes it to an object.
Gets the next informed queue ' s message and deserializes it to an object .
Occurs when the connection to the server fails.
Occurs when the connection to the server fails .
queueName
string
config
IMessagingConfig
The queue configuration.
The queue configuration .
typeparam
The type to which the message will be deserialized to.
The type to which the message will be deserialized to .