protected void Flush() { foreach (var message in _bufferList) { _dispatcher.EnqueueToPublish(message); } }
public void OnNext(KeyValuePair <string, object> evt) { if (evt.Key == SqlAfterCommitTransactionMicrosoft) { if (!TryGetSqlConnection(evt, out SqlConnection sqlConnection)) { return; } var transactionKey = sqlConnection.ClientConnectionId; if (_bufferList.TryRemove(transactionKey, out var msgList)) { foreach (var message in msgList) { _dispatcher.EnqueueToPublish(message); } } } else if (evt.Key == SqlErrorCommitTransactionMicrosoft) { if (!TryGetSqlConnection(evt, out SqlConnection sqlConnection)) { return; } var transactionKey = sqlConnection.ClientConnectionId; _bufferList.TryRemove(transactionKey, out _); } }
protected virtual void Flush() { while (!_bufferList.IsEmpty) { _bufferList.TryDequeue(out var message); _dispatcher.EnqueueToPublish(message); } }
protected async Task PublishAsyncInternal(CapPublishedMessage message) { var operationId = default(Guid); try { var tracingResult = TracingBefore(message.Name, message.Content); operationId = tracingResult.Item1; message.Content = tracingResult.Item2 != null ? Helper.AddTracingHeaderProperty(message.Content, tracingResult.Item2) : message.Content; if (Transaction.Value?.DbTransaction == null) { await ExecuteAsync(message); s_diagnosticListener.WritePublishMessageStoreAfter(operationId, message); _dispatcher.EnqueueToPublish(message); } else { var transaction = (CapTransactionBase)Transaction.Value; await ExecuteAsync(message, transaction); s_diagnosticListener.WritePublishMessageStoreAfter(operationId, message); transaction.AddToSent(message); if (transaction.AutoCommit) { transaction.Commit(); } } } catch (Exception e) { s_diagnosticListener.WritePublishMessageStoreError(operationId, message, e); throw; } }
public async Task ExecuteAsync(OutgoingPipelineContext ctx, Func <Task> next) { var message = ctx.Load <Messages.Message>(); var dbMessage = await _dataStorage.StoreMessageToSendAsync(message.Body, message.Headers); Action callDispatcher = () => _dispatcher.EnqueueToPublish(message, dbMessage.Id); if (Transaction.Current != null) { Transactions.GenericTransaction.EnlistTransaction( null, callDispatcher, null, null ); } else { callDispatcher(); } }
public void OnNext(KeyValuePair <string, object?> evt) { switch (evt.Key) { case SqlAfterCommitTransactionMicrosoft: { if (!TryGetSqlConnection(evt, out SqlConnection? sqlConnection)) { return; } var transactionKey = sqlConnection.ClientConnectionId; if (_bufferList.TryRemove(transactionKey, out var msgList)) { foreach (var message in msgList) { _dispatcher.EnqueueToPublish(message); } } break; } case SqlErrorCommitTransactionMicrosoft or SqlAfterRollbackTransactionMicrosoft or SqlBeforeCloseConnectionMicrosoft: { if (!_bufferList.IsEmpty) { if (!TryGetSqlConnection(evt, out SqlConnection? sqlConnection)) { return; } var transactionKey = sqlConnection.ClientConnectionId; _bufferList.TryRemove(transactionKey, out _); } break; } } }
public void OnNext(KeyValuePair <string, object> evt) { if (evt.Key == SqlAfterCommitTransaction) { var sqlConnection = (SqlConnection)GetProperty(evt.Value, "Connection"); var transactionKey = sqlConnection.ClientConnectionId; if (_bufferList.TryRemove(transactionKey, out var msgList)) { foreach (var message in msgList) { _dispatcher.EnqueueToPublish(message); } } } else if (evt.Key == SqlErrorCommitTransaction) { var sqlConnection = (SqlConnection)GetProperty(evt.Value, "Connection"); var transactionKey = sqlConnection.ClientConnectionId; _bufferList.TryRemove(transactionKey, out _); } }
protected async Task PublishAsyncInternal(CapPublishedMessage message) { var operationId = default(Guid); try { operationId = s_diagnosticListener.WritePublishMessageStoreBefore(message); if (Transaction.Value?.DbTransaction == null) { await ExecuteAsync(message); s_diagnosticListener.WritePublishMessageStoreAfter(operationId, message); _dispatcher.EnqueueToPublish(message); } else { var transaction = (CapTransactionBase)Transaction.Value; await ExecuteAsync(message, transaction); s_diagnosticListener.WritePublishMessageStoreAfter(operationId, message); transaction.AddToSent(message); if (transaction.AutoCommit) { transaction.Commit(); } } } catch (Exception e) { s_diagnosticListener.WritePublishMessageStoreError(operationId, message, e); throw; } }
public void Publish <T>(string name, T value, IDictionary <string, string> headers) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } if (headers == null) { headers = new Dictionary <string, string>(); } var messageId = SnowflakeId.Default().NextId().ToString(); headers.Add(Headers.MessageId, messageId); headers.Add(Headers.MessageName, name); headers.Add(Headers.Type, typeof(T).FullName); headers.Add(Headers.SentTime, DateTimeOffset.Now.ToString()); if (!headers.ContainsKey(Headers.CorrelationId)) { headers.Add(Headers.CorrelationId, messageId); headers.Add(Headers.CorrelationSequence, 0.ToString()); } var message = new Message(headers, value); long?tracingTimestamp = null; try { tracingTimestamp = TracingBefore(message); if (Transaction.Value?.DbTransaction == null) { var mediumMessage = _storage.StoreMessage(name, message); TracingAfter(tracingTimestamp, message); _dispatcher.EnqueueToPublish(mediumMessage); } else { var transaction = (CapTransactionBase)Transaction.Value; var mediumMessage = _storage.StoreMessage(name, message, transaction.DbTransaction); TracingAfter(tracingTimestamp, message); transaction.AddToSent(mediumMessage); if (transaction.AutoCommit) { transaction.Commit(); } } } catch (Exception e) { TracingError(tracingTimestamp, message, e); throw; } }
protected void Enqueue(CapPublishedMessage message) { _dispatcher.EnqueueToPublish(message); }