public IFatpipeMessage GetSuspendedMessage(string messageIdentifier) { string location = "FpmDal->GetSuspendedMessage"; IFatpipeMessage result = null; SuspendedMessageEntity suspendedMessage = null; try { Stopwatch watch = Stopwatch.StartNew(); suspendedMessage = (from e in this.suspendedTableServiceContext.CreateQuery <SuspendedMessageEntity>(MaargConfiguration.Instance[MaargConfiguration.SuspendedMessageTableName]) where e.RowKey == messageIdentifier select e).FirstOrDefault(); if (suspendedMessage != null) { IFatpipeMessage message = null; CloudBlob blob = this.suspendedContainer.GetBlobReference(suspendedMessage.SuspendedMessageBlobReference); using (MemoryStream stream = new MemoryStream()) { blob.DownloadToStream(stream); stream.Position = 0; message = BizpipeMesssageStreaming.CreateBizpipeMessageFromStream(stream, this.fpm); } if (!string.IsNullOrEmpty(suspendedMessage.PartnerIdentifier)) { IOutboundFatpipeMessage outboundMessage = this.fpm.CreateNewOutboundMessage(); outboundMessage.Header = message.Header; outboundMessage.Body = message.Body; outboundMessage.Status = message.Status; outboundMessage.RoutingInfo = new RoutingInfo(); outboundMessage.RoutingInfo.PartnerId = suspendedMessage.PartnerIdentifier; outboundMessage.RoutingInfo.TransportType = TransportType.Suspend; result = outboundMessage; } else { result = message; } } watch.Stop(); LoggerFactory.Logger.Debug(location, "Message {0} retrieved from suspended queue in {1} ms.", messageIdentifier, watch.ElapsedMilliseconds); } catch (Exception exception) { LoggerFactory.Logger.Error(location, EventId.BizpipeGetSuspendMessage , "Error getting the suspended message {0}: {1}." , messageIdentifier , exception.ToString()); } return(result); }
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 IFatpipeMessage Dequeue(Constants.QueueType type) { string location = "FpmDal->Dequeue"; IFatpipeMessage fatpipeMessage = null; bool inbound = (type == Constants.QueueType.INBOUND); CloudQueue queue = inbound ? this.incomingQ : this.outgoingQ; CloudBlobContainer container = inbound ? this.inContainer : this.outContainer; try { Stopwatch watch = Stopwatch.StartNew(); CloudQueueMessage entry = queue.GetMessage(this.visibilityTimeout); if (entry != null) { watch.Stop(); LoggerFactory.Logger.Info(location + (inbound ? "->B2BEngineReadingFromIncomingQ" : "OutboundTransportReadingFromOutgoingQ"), "timeInMs={0}, entry={1}", watch.ElapsedMilliseconds, entry.AsString); byte[] buffer = null; bool isInlineContent = inbound ? GetContent(entry, out buffer) : false; MemoryStream blobStream = null; if (isInlineContent) { blobStream = new MemoryStream(buffer); } else { watch = Stopwatch.StartNew(); string blobName = entry.AsString; CloudBlob blob = container.GetBlobReference(blobName); BlobRequestOptions options = new BlobRequestOptions(); blobStream = new MemoryStream(); blob.DownloadToStream(blobStream); watch.Stop(); LoggerFactory.Logger.Info(location + (inbound ? "->B2BEngineReadingFromIncomingBlob" : "OutboundTransportReadingFromOutgoingBlob"), "timeInMs={0}, blob={1}", watch.ElapsedMilliseconds, blobName); } blobStream.Position = 0; //msg = DecodeBlobPayload(blobStream, this.fpm); fatpipeMessage = BizpipeMesssageStreaming.CreateBizpipeMessageFromStream(blobStream, this.fpm); // set the QueueName and the queue message identifiers fatpipeMessage.Header.QueueName = (inbound == true) ? incomingQ.Name : outgoingQ.Name; fatpipeMessage.Header.QueueMessageId = entry.Id; fatpipeMessage.Header.QueueMessagePopReceipt = entry.PopReceipt; fatpipeMessage.Status.NumberOfRetryAttempts = entry.DequeueCount; } } catch (Exception ex) { LoggerFactory.Logger.Warning(location, EventId.BizpipeDequeueMessage , "Exception encountered during Dequeue operation: {0}", ex.ToString()); } return(fatpipeMessage); }
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); }