public T Pull() { using (var channel = MQFactory.Connection.CreateModel()) { channel.QueueDeclare(queue: QueueName, durable: true, exclusive: false, autoDelete: false, arguments: null); channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false); BasicGetResult result = channel.BasicGet(QueueName, false); if (result != null) { T model = ByteArrayHelpler.ByteArrayToObject <T>(result.Body); channel.BasicAck(result.DeliveryTag, false); return(model); } } return(default(T)); }
public bool Pull(Func <T, bool> excuteMessage) { try { using (var channel = MQFactory.Connection.CreateModel()) { channel.QueueDeclare(queue: QueueName, durable: true, exclusive: false, autoDelete: false, arguments: null); channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false); BasicGetResult result = channel.BasicGet(QueueName, false); if (result != null) { T msg = ByteArrayHelpler.ByteArrayToObject <T>(result.Body); if (excuteMessage(msg)) { // đánh dấu đã đọc msg này channel.BasicAck(result.DeliveryTag, false); return(true); } else { return(false); } } else { return(false); } } } catch { return(false); } }