/// <summary> /// Transmits a message. /// </summary> /// <param name="msg">The message to transmit.</param> public void TransmitMessage(MultiPartMessage msg) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().Name); } if (!_isRunning) { throw new InvalidOperationException("Message Engine is not running."); } CheckMetadata(msg); AdapterBase adapter = AdapterProxy.GetAdapterById(msg.Metadata.ReadAsString("SendAdapterId")); ComponentPipeline pipeline = _sendPipelineDictionary[adapter]; Collection <MultiPartMessage> resultCollection = pipeline.Execute(msg); if (resultCollection != null) { //Check if message should be part of a transaction if (TransactionScope.Current != null) { if (adapter is ITransactional) { ITransactional transactionalAdapter = adapter as ITransactional; AdapterTransaction transaction = transactionalAdapter.StartTransaction(resultCollection[0]); transaction.State = TransactionState.Started; TransactionScope.Current.EnlistTransaction(transaction); transactionalAdapter.TransmitMessage(resultCollection[0], transaction); } else { throw new AdapterException("Adapter: \"" + adapter.AdapterId + "\" is not transactional."); } } else { adapter.TransmitMessage(resultCollection[0]); } } }
private void MessageReceivedEventHandler(object sender, AdapterReceiveEventArgs e) { if (!_isRunning) { return; } MultiPartMessage msg = e.Message; try { //Block incoming messages if startup in progress _blockThreadsWaitEvent.WaitOne(); //Create message metadata msg.Metadata.Write("ReceiveUri", e.ReceiveEndPoint.Uri); msg.Metadata.Write("ReceiveAdapterId", e.ReceiveEndPoint.Adapter.AdapterId); ComponentPipeline pipeline = _receivePipelineDictionary[e.ReceiveEndPoint.Adapter]; Collection <MultiPartMessage> resultCollection = pipeline.Execute(msg); if (resultCollection != null) { List <CorrelationContext> contextCollection = new List <CorrelationContext>(); foreach (MultiPartMessage resultMsg in resultCollection) { CorrelationContext context = CorrelateMessage(resultMsg); if (context == null) { SubscriptionManager.DistributeMessage(resultMsg); } else { contextCollection.Add(context); } } foreach (CorrelationContext context in contextCollection) { //Signal the requestor thread that a response has been received context.CompleteRequest(); } } } catch (Exception ex) { if (ExceptionHelper.IsCritical(ex)) { throw; } else if ((MessageEngine.Instance.Tracing.Switch.Level & SourceLevels.Error) == SourceLevels.Error && _isRunning) { if (msg != null) { MessageEngine.Instance.Tracing.TraceData(TraceEventType.Error, msg.GetHashCode(), ex); } else { MessageEngine.Instance.Tracing.TraceData(TraceEventType.Error, 0, ex); } } } }