public void Acknowledge(InboundMessageDispatch envelope, AckType ackType) { if (envelope.Message.Facade is AmqpNmsMessageFacade facade) { global::Amqp.Message message = facade.Message; switch (ackType) { case AckType.DELIVERED: envelope.IsDelivered = true; break; case AckType.ACCEPTED: HandleAccepted(envelope, message); break; case AckType.RELEASED: receiverLink.Release(message); RemoveMessage(envelope); break; case AckType.MODIFIED_FAILED_UNDELIVERABLE: receiverLink.Modify(message, true, true); RemoveMessage(envelope); break; default: Tracer.ErrorFormat("Unsupported Ack Type for message: {0}", envelope); throw new ArgumentException($"Unsupported Ack Type for message: {envelope}"); } } else { Tracer.ErrorFormat($"Received Ack for unknown message: {envelope}"); } }
public Task Acknowledge(InboundMessageDispatch envelope, AckType ackType) { AmqpSession session = connection.GetSession(envelope.ConsumerInfo.SessionId); AmqpConsumer consumer = session.GetConsumer(envelope.ConsumerId); consumer.Acknowledge(envelope, ackType); return Task.CompletedTask; }
public void Acknowledge(AckType ackType) { foreach (InboundMessageDispatch envelope in GetMessages().Where(x => x.IsDelivered)) { Acknowledge(envelope, ackType); } }
/// <summary> /// Initializes a new instance of the <see cref="AckEventArgs{T, U}"/> class. /// </summary> /// <param name="interchangeHeader">The interchange header.</param> /// <param name="groupHeader">The group header.</param> /// <param name="message">The EDI message.</param> /// <param name="ackType">The acknowledgment type.</param> protected AckEventArgs(T interchangeHeader, U groupHeader, EdiMessage message, AckType ackType) { InterchangeHeader = interchangeHeader; GroupHeader = groupHeader; Message = message; AckType = ackType; }
public ReconsumeLaterWithProperties(IMessage <T> message, AckType ackType, IDictionary <string, long> properties, long delayTime) { Message = message; Properties = properties.ToImmutableDictionary(); DelayTime = delayTime; AckType = ackType; }
private static Segment GetMSASegment(string messageID, string error, AckType ackType) { Segment MSH = new Segment(); MSH[new ControlCharacters()] = string.Format("MSA|{0}|{1}|{2}", ackType, messageID, error); return(MSH); }
public void AcknowledgeIndividual(AckType ackType, InboundMessageDispatch envelope) { if (Transacted) { throw new IllegalStateException("Message acknowledge called inside a transacted Session"); } Connection.Acknowledge(envelope, ackType); }
private static ACKDATA BuildAckData(IntPtr pModuleName, AckType type, bool success, IntPtr contactHandle, IntPtr processHandle, IntPtr lParam) { ACKDATA ack = new ACKDATA(pModuleName, (int)type, success ? (int)AckResult.Success : (int)AckResult.Failure); ack.ContactHandle = contactHandle; ack.ProcessHandle = processHandle; ack.LParam = lParam; return ack; }
public static AckMessage GetAckMessage(string messageID, AckType ackType, string error = "") { AckMessage message = new AckMessage(); message.Segments.Add(GetMSHSegment(string.Empty, "ACK")); message.Segments.Add(GetMSASegment(messageID, error, ackType)); return(message); }
public Task Acknowledge(Id sessionId, AckType ackType) { AmqpSession session = connection.GetSession(sessionId); foreach (AmqpConsumer consumer in session.Consumers) { consumer.Acknowledge(ackType); } return Task.CompletedTask; }
private async ValueTask AddListAcknowledgment(IList <IMessageId> messageIds, AckType ackType, IDictionary <string, long> properties) { if (ackType == AckType.Cumulative) { var cnx = await Cnx(); if (await IsAckReceiptEnabled(cnx)) { ISet <Task> taskSet = new HashSet <Task>(); messageIds.ForEach(messageId => taskSet.Add(AddAcknowledgment(messageId, ackType, properties).AsTask())); Task.WaitAll(taskSet.ToArray()); } else { messageIds.ForEach(async messageId => await AddAcknowledgment(messageId, ackType, properties)); } } else { var cnx = await Cnx(); if (await IsAckReceiptEnabled(cnx)) { // when flush the ack, we should bind the this ack in the currentFuture, during this time we can't // change currentFuture. but we can lock by the read lock, because the currentFuture is not change // any ack operation is allowed. try { if (messageIds.Count != 0) { AddListAcknowledgment(messageIds); } } finally { if (_acknowledgementGroupTimeMicros == 0 || _pendingIndividualAcks.Count >= MaxAckGroupSize) { await Flush(); } } } else { AddListAcknowledgment(messageIds); if (_acknowledgementGroupTimeMicros == 0 || _pendingIndividualAcks.Count >= MaxAckGroupSize) { await Flush(); } } } }
private async ValueTask DoImmediateAck(MessageId msgId, AckType ackType, IDictionary <string, long> properties, long[] bitSet) { var cnx = await Cnx(); if (cnx == null) { Context.System.Log.Error("Consumer connect fail!"); } else { await NewImmediateAckAndFlush(_consumerId, msgId, bitSet, ackType, properties, cnx); } }
public static int BroadcastAck(string moduleName, AckType type, bool success, IntPtr contactHandle, IntPtr processHandle, IntPtr lParam) { UnmanagedStringHandle pModuleName = UnmanagedStringHandle.Empty; try { pModuleName = new UnmanagedStringHandle(moduleName, StringEncoding.Ansi); return BroadcastAck(pModuleName.IntPtr, type, success, contactHandle, processHandle, lParam); } finally { pModuleName.Free(); } }
public Task Acknowledge(InboundMessageDispatch envelope, AckType ackType) { CheckClosed(); FailoverRequest request = new FailoverRequest(this, requestTimeout) { DoTask = activeProvider => activeProvider.Acknowledge(envelope, ackType), FailureWhenOffline = true, Name = nameof(Acknowledge) }; request.Run(); return(request.Task); }
public Task Acknowledge(NmsSessionId sessionId, AckType ackType) { CheckClosed(); FailoverRequest request = new FailoverRequest(this, requestTimeout) { DoTask = activeProvider => activeProvider.Acknowledge(sessionId, ackType), FailureWhenOffline = true, Name = nameof(Acknowledge) }; request.Run(); return(request.Task); }
private void AckReply(AckType ackType, long delayNanoseconds, int timeout) { if (AckHasntBeenTermed()) { // very important, must use _reply variable, not public Reply property if (timeout >= 0) { Connection.Request(_reply, ackType.BodyBytes(delayNanoseconds), timeout); } else { Connection.Publish(_reply, ackType.BodyBytes(delayNanoseconds)); } _lastAck = ackType; } }
public void Acknowledge(InboundMessageDispatch envelope, AckType ackType) { if (envelope.Message.Facade is AmqpNmsMessageFacade facade) { global::Amqp.Message message = facade.Message; switch (ackType) { case AckType.DELIVERED: envelope.IsDelivered = true; break; case AckType.ACCEPTED: AmqpTransactionContext transactionalState = session.TransactionContext; if (transactionalState != null) { receiverLink.Complete(message, transactionalState.GetTxnAcceptState()); transactionalState.RegisterTxConsumer(this); } else { receiverLink.Accept(message); } RemoveMessage(envelope); break; case AckType.RELEASED: receiverLink.Release(message); RemoveMessage(envelope); break; case AckType.MODIFIED_FAILED_UNDELIVERABLE: receiverLink.Modify(message, true, true); RemoveMessage(envelope); break; default: Tracer.Error($"Unsupported Ack Type for message: {envelope.Message}"); throw new ArgumentException($"Unsupported Ack Type for message: {envelope.Message}"); } } else { Tracer.ErrorFormat($"Received Ack for unknown message: {envelope}"); } }
private MessageAck MakeAckForAllDeliveredMessages(AckType type) { lock (this.dispatchedMessages) { if (this.dispatchedMessages.Count == 0) { return(null); } MessageDispatch dispatch = this.dispatchedMessages.First.Value; MessageAck ack = new MessageAck(); ack.AckType = (byte)type; ack.ConsumerId = this.info.ConsumerId; ack.Destination = dispatch.Destination; ack.LastMessageId = dispatch.Message.MessageId; ack.MessageCount = this.dispatchedMessages.Count; ack.FirstMessageId = this.dispatchedMessages.Last.Value.Message.MessageId; return(ack); } }
public async Task Acknowledge(InboundMessageDispatch envelope, AckType ackType) { // Consumed or delivered messages fall into a transaction otherwise just pass it in. if (ackType == AckType.ACCEPTED || ackType == AckType.DELIVERED) { try { await this.connection.Acknowledge(envelope, ackType).ConfigureAwait(false); this.participants.Add(envelope.ConsumerId); Tracer.Debug($"TX:{this.transactionInfo.Id} has performed an acknowledge."); } catch (Exception) { Tracer.Debug($"TX:{this.transactionInfo.Id} has failed an acknowledge."); this.participants.Add(envelope.ConsumerId); throw; } } else { await this.connection.Acknowledge(envelope, ackType).ConfigureAwait(false); } }
private void AckLater(MessageDispatch dispatch, AckType type) { // Don't acknowledge now, but we may need to let the broker know the // consumer got the message to expand the pre-fetch window if (this.session.IsTransacted) { this.session.DoStartTransaction(); if (!synchronizationRegistered) { Tracer.DebugFormat("Consumer {0} Registering new MessageConsumerSynchronization", this.info.ConsumerId); this.synchronizationRegistered = true; this.session.TransactionContext.AddSynchronization(new MessageConsumerSynchronization(this)); } } this.deliveredCounter++; MessageAck oldPendingAck = pendingAck; pendingAck = new MessageAck(); pendingAck.AckType = (byte)type; pendingAck.ConsumerId = this.info.ConsumerId; pendingAck.Destination = dispatch.Destination; pendingAck.LastMessageId = dispatch.Message.MessageId; pendingAck.MessageCount = deliveredCounter; if (this.session.IsTransacted && this.session.TransactionContext.InTransaction) { pendingAck.TransactionId = this.session.TransactionContext.TransactionId; } if (oldPendingAck == null) { pendingAck.FirstMessageId = pendingAck.LastMessageId; } else if (oldPendingAck.AckType == pendingAck.AckType) { pendingAck.FirstMessageId = oldPendingAck.FirstMessageId; } else { // old pending ack being superseded by ack of another type, if is is not a delivered // ack and hence important, send it now so it is not lost. if (oldPendingAck.AckType != (byte)AckType.DeliveredAck) { if (Tracer.IsDebugEnabled) { Tracer.Debug("Sending old pending ack " + oldPendingAck + ", new pending: " + pendingAck); } this.session.Connection.Oneway(oldPendingAck); } else { if (Tracer.IsDebugEnabled) { Tracer.Debug("dropping old pending ack " + oldPendingAck + ", new pending: " + pendingAck); } } } if ((0.5 * this.info.PrefetchSize) <= (this.deliveredCounter - this.additionalWindowSize)) { this.session.Connection.Oneway(pendingAck); this.pendingAck = null; this.deliveredCounter = 0; this.additionalWindowSize = 0; } }
private async ValueTask AddAcknowledgment(IMessageId msgId, AckType ackType, IDictionary <string, long> properties) { if (msgId is BatchMessageId batchMessageId) { if (ackType == AckType.Individual) { _consumer.Tell(new OnAcknowledge(batchMessageId, null)); // ack this ack carry bitSet index and judge bit set are all ack if (batchMessageId.AckIndividual()) { var messageId = ModifyBatchMessageIdAndStatesInConsumer(batchMessageId); await DoIndividualAck(messageId, properties); } else if (_batchIndexAckEnabled) { await DoIndividualBatchAck(batchMessageId, properties); } else { // if we prevent batchIndexAck, we can't send the ack command to broker when the batch message are // all ack complete return;// CompletableFuture.completedFuture(null); } } else { _consumer.Tell(new OnAcknowledgeCumulative(batchMessageId, null)); if (batchMessageId.AckCumulative()) { await DoCumulativeAck(batchMessageId, properties, null); } else { if (_batchIndexAckEnabled) { await DoCumulativeBatchIndexAck(batchMessageId, properties); } else { // ack the pre messageId, because we prevent the batchIndexAck, we can ensure pre messageId can // ack if (AckType.Cumulative == ackType && !batchMessageId.Acker.PrevBatchCumulativelyAcked) { await DoCumulativeAck(batchMessageId.PrevBatchMessageId(), properties, null); batchMessageId.Acker.PrevBatchCumulativelyAcked = true; } } } } } else { if (ackType == AckType.Individual) { _consumer.Tell(new OnAcknowledge(msgId, null)); ModifyMessageIdStatesInConsumer((MessageId)msgId); await DoIndividualAck((MessageId)msgId, properties); } else { _consumer.Tell(new OnAcknowledgeCumulative(msgId, null)); await DoCumulativeAck((MessageId)msgId, properties, null); } } }
public Task Acknowledge(InboundMessageDispatch envelope, AckType ackType) { throw new NotImplementedException(); }
public Builder SetAckType(AckType value) { _ack.ack_type = value; return(this); }
public static unsafe int BroadcastAck(IntPtr pModuleName, AckType type, bool success, IntPtr contactHandle, IntPtr processHandle, IntPtr lParam) { ACKDATA ack = BuildAckData(pModuleName, type, success, contactHandle, processHandle, lParam); return BroadcastAck(&ack); }
public Task Acknowledge(Id sessionId, AckType ackType) { throw new NotImplementedException(); }
private void AckLater(MessageDispatch dispatch, AckType type) { // Don't acknowledge now, but we may need to let the broker know the // consumer got the message to expand the pre-fetch window if(this.session.IsTransacted) { this.session.DoStartTransaction(); if(!synchronizationRegistered) { Tracer.DebugFormat("Consumer {0} Registering new MessageConsumerSynchronization", this.info.ConsumerId); this.synchronizationRegistered = true; this.session.TransactionContext.AddSynchronization(new MessageConsumerSynchronization(this)); } } this.deliveredCounter++; MessageAck oldPendingAck = pendingAck; pendingAck = new MessageAck(); pendingAck.AckType = (byte) type; pendingAck.ConsumerId = this.info.ConsumerId; pendingAck.Destination = dispatch.Destination; pendingAck.LastMessageId = dispatch.Message.MessageId; pendingAck.MessageCount = deliveredCounter; if(this.session.IsTransacted && this.session.TransactionContext.InTransaction) { pendingAck.TransactionId = this.session.TransactionContext.TransactionId; } if(oldPendingAck == null) { pendingAck.FirstMessageId = pendingAck.LastMessageId; } else if(oldPendingAck.AckType == pendingAck.AckType) { pendingAck.FirstMessageId = oldPendingAck.FirstMessageId; } else { // old pending ack being superseded by ack of another type, if is is not a delivered // ack and hence important, send it now so it is not lost. if(oldPendingAck.AckType != (byte) AckType.DeliveredAck) { if(Tracer.IsDebugEnabled) { Tracer.Debug("Sending old pending ack " + oldPendingAck + ", new pending: " + pendingAck); } this.session.Connection.Oneway(oldPendingAck); } else { if(Tracer.IsDebugEnabled) { Tracer.Debug("dropping old pending ack " + oldPendingAck + ", new pending: " + pendingAck); } } } if((0.5 * this.info.PrefetchSize) <= (this.deliveredCounter - this.additionalWindowSize)) { this.session.Connection.Oneway(pendingAck); this.pendingAck = null; this.deliveredCounter = 0; this.additionalWindowSize = 0; } }
public Task Acknowledge(InboundMessageDispatch envelope, AckType ackType) { return(this.session.Connection.Acknowledge(envelope, ackType)); }
private async ValueTask NewMessageAckCommandAndWrite(IActorRef cnx, long consumerId, long ledgerId, long entryId, long[] ackSet, AckType ackType, ValidationError?validationError, IDictionary <string, long> properties, bool flush, IList <(long LedgerId, long EntryId, long[] Sets)> entriesToAck)
private async ValueTask DoImmediateBatchIndexAck(BatchMessageId msgId, int batchIndex, int batchSize, AckType ackType, IDictionary <string, long> properties) { var cnx = await Cnx(); if (cnx == null) { Context.System.Log.Error("Consumer connect fail!"); return; } BitArray bitSet; if (msgId.Acker != null && !(msgId.Acker is BatchMessageAckerDisabled)) { bitSet = new BitArray(msgId.Acker.BatchSize, true); } else { bitSet = new BitArray(batchSize, true); } if (ackType == AckType.Cumulative) { for (var j = 0; j <= batchIndex; j++) { bitSet[j] = false; } } else { bitSet[batchIndex] = false; } await NewMessageAckCommandAndWrite(cnx, _consumerId, msgId.LedgerId, msgId.EntryId, bitSet.ToLongArray(), ackType, null, properties, true, null); }
/// <summary> /// 应答处理 /// </summary> /// <param name="sender">发起消息的对象</param> /// <param name="index">当前消息的序列</param> /// <param name="multipleAck">是否批量应答</param> /// <param name="ackType">回应类型</param> /// <returns>应答是否成功</returns> public bool AfterReceive(object sender, ulong index, bool multipleAck = false, AckType ackType = AckType.SuccessAndDelete) { try { var channel = ((EventingBasicConsumer)sender).Model; switch (ackType) { case AckType.SuccessAndDelete: channel.BasicAck(index, multipleAck); break; case AckType.FailButDelete: channel.BasicNack(index, multipleAck, false); break; case AckType.FailButRequeue: channel.BasicNack(index, multipleAck, true); break; case AckType.FailButRequeueAndNewConsumer: channel.BasicRecover(true); break; case AckType.FailButRequeueAndSameConsumer: channel.BasicRecover(false); break; default: channel.BasicAck(index, multipleAck); break; } return(true); } catch { return(false); } }
public void Acknowledge(AckType ackType, InboundMessageDispatch envelope) { Connection.Acknowledge(envelope, ackType).ConfigureAwait(false).GetAwaiter().GetResult(); }
private async ValueTask NewImmediateAckAndFlush(long consumerId, MessageId msgId, long[] bitSet, AckType ackType, IDictionary <string, long> map, IActorRef cnx) { var response = await _unAckedChunckedMessageIdSequenceMap.Ask <UnAckedChunckedMessageIdSequenceMapCmdResponse>(new UnAckedChunckedMessageIdSequenceMapCmd(UnAckedCommand.GetRemoved, new List <IMessageId> { msgId })).ConfigureAwait(false); var chunkMsgIds = response.MessageIds; // cumulative ack chunk by the last messageId if (chunkMsgIds != null && ackType != AckType.Cumulative) { var version = await cnx.Ask <RemoteEndpointProtocolVersionResponse>(RemoteEndpointProtocolVersion.Instance); var protocolVersion = version.Version; if (Commands.PeerSupportsMultiMessageAcknowledgment(protocolVersion)) { var entriesToAck = new List <(long LedgerId, long EntryId, long[] Sets)>(chunkMsgIds.Length); foreach (MessageId cMsgId in chunkMsgIds) { if (cMsgId != null && chunkMsgIds.Length > 1) { entriesToAck.Add((cMsgId.LedgerId, cMsgId.EntryId, null)); } } await NewMessageAckCommandAndWrite(cnx, _consumerId, 0L, 0L, null, ackType, null, null, true, entriesToAck); } else { // if don't support multi message ack, it also support ack receipt, so we should not think about the // ack receipt in this logic foreach (MessageId cMsgId in chunkMsgIds) { await NewMessageAckCommandAndWrite(cnx, consumerId, cMsgId.LedgerId, cMsgId.EntryId, bitSet, ackType, null, map, true, null); } } } else { await NewMessageAckCommandAndWrite(cnx, consumerId, msgId.LedgerId, msgId.EntryId, bitSet, ackType, null, map, true, null); } }
public void Acknowledge(AckType ackType) { Connection.Acknowledge(SessionInfo.Id, ackType); }
private MessageAck MakeAckForAllDeliveredMessages(AckType type) { lock(this.dispatchedMessages) { if(this.dispatchedMessages.Count == 0) { return null; } MessageDispatch dispatch = this.dispatchedMessages.First.Value; MessageAck ack = new MessageAck(); ack.AckType = (byte) type; ack.ConsumerId = this.info.ConsumerId; ack.Destination = dispatch.Destination; ack.LastMessageId = dispatch.Message.MessageId; ack.MessageCount = this.dispatchedMessages.Count; ack.FirstMessageId = this.dispatchedMessages.Last.Value.Message.MessageId; return ack; } }