public bool SaveSuspendedMessage(IFatpipeMessage message) { string location = "FpmDal->SaveSuspendedMessage"; bool result = true; SuspendedMessageEntity suspendedMessage = null; //TODO remove the return statement // don't want any message to be suspended return(true); try { Stopwatch watch = Stopwatch.StartNew(); suspendedMessage = new SuspendedMessageEntity(message.Header.TenantIdentifier, message.Header.Identifier); suspendedMessage.Timestamp = DateTime.UtcNow; suspendedMessage.SuspendedMessageBlobReference = message.Header.Identifier; if (message.Status != null) { suspendedMessage.ErrorMessage = string.Format(CultureInfo.InvariantCulture, "{0}. Message suspended after {1} retries. Error: {2}", message.Status.ProcessingResult, message.Status.NumberOfRetryAttempts, message.Status.ErrorDescription); } IOutboundFatpipeMessage outboundMessage = message as IOutboundFatpipeMessage; if (outboundMessage != null) { if (outboundMessage.RoutingInfo != null) { suspendedMessage.PartnerIdentifier = outboundMessage.RoutingInfo.PartnerId; } } this.suspendedTableServiceContext.AddObject(MaargConfiguration.Instance[MaargConfiguration.SuspendedMessageTableName], suspendedMessage); //save to suspended table and blob DataServiceResponse response = this.suspendedTableServiceContext.SaveChangesWithRetries(); // The entry in the Q is the message blob name using (Stream stream = BizpipeMesssageStreaming.WriteBizpipeMessageToStream(message)) { CloudBlob blob = this.suspendedContainer.GetBlobReference(suspendedMessage.SuspendedMessageBlobReference); blob.UploadFromStream(stream); } watch.Stop(); LoggerFactory.Logger.Debug(location, "Message {0} saved to suspended queue in {1} ms.", message.Header.Identifier, watch.ElapsedMilliseconds); } catch (Exception exception) { LoggerFactory.Logger.Error(location, EventId.BizpipeSaveSuspendMessage , "Exception encountered during suspended message operation: {0}." , exception.ToString()); result = false; } return(result); }
public bool Enqueue(IFatpipeMessage msg, Constants.QueueType type) { string location = "FpmDal->Enqueue"; Stopwatch watch; try { // store the entire message in Blob string blobName = msg.Header.Identifier; CloudBlob blob; bool inbound = (type == Constants.QueueType.INBOUND); Stream blobStream = BizpipeMesssageStreaming.WriteBizpipeMessageToStream(msg); // The entry in the Q is the message blob name CloudQueueMessage entry = new CloudQueueMessage(blobName); //SetQueueBodyData(entry, blobStream); if (inbound) { //Measure and write to blob storage watch = Stopwatch.StartNew(); blob = inContainer.GetBlobReference(blobName); blob.UploadFromStream(blobStream); watch.Stop(); LoggerFactory.Logger.Info(location + "->SaveToIncomingBlob", "timeInMs={0} blobName={1}", watch.ElapsedMilliseconds, blobName); //Measure and write to incomingQ watch = Stopwatch.StartNew(); incomingQ.AddMessage(entry); watch.Stop(); LoggerFactory.Logger.Info(location + "->WriteToIncomingQ", "timeInMs={0} entry={1}", watch.ElapsedMilliseconds, blobName); } else { //Measure and write to blob storage watch = Stopwatch.StartNew(); blob = outContainer.GetBlobReference(blobName); blob.UploadFromStream(blobStream); watch.Stop(); LoggerFactory.Logger.Info(location + "->B2BEngineWritingToOutgoingBlob", "timeInMs={0}, blob={1}", watch.ElapsedMilliseconds, blobName); //Measure and write to incomingQ watch = Stopwatch.StartNew(); outgoingQ.AddMessage(entry); watch.Stop(); LoggerFactory.Logger.Info(location + "->B2BEngineWritingToOutgoingQ", "timeInMs={0}, entry={1}", watch.ElapsedMilliseconds, blobName); } // set the QueueName and the queue message identifiers msg.Header.QueueName = (inbound == true) ? incomingQ.Name : outgoingQ.Name; msg.Header.QueueMessageId = entry.Id; msg.Header.QueueMessagePopReceipt = entry.PopReceipt; } catch (Exception ex) { LoggerFactory.Logger.Warning(location, EventId.BizpipeEnqueueMessage , "Exception encountered during Enqueue operation: {0}", ex.ToString()); return(false); } return(true); }