public Task Init(Func <PushContext, Task> pipe, CriticalError criticalError, PushSettings settings)
 {
     pipeline       = pipe;
     path           = BaseDirectoryBuilder.BuildBasePath(settings.InputQueue);
     purgeOnStartup = settings.PurgeOnStartup;
     return(TaskEx.CompletedTask);
 }
    public Task Dispatch(TransportOperations outgoingMessages, TransportTransaction transaction, ContextBag context)
    {
        foreach (var operation in outgoingMessages.UnicastTransportOperations)
        {
            var basePath        = BaseDirectoryBuilder.BuildBasePath(operation.Destination);
            var nativeMessageId = Guid.NewGuid().ToString();
            var bodyPath        = Path.Combine(basePath, ".bodies", $"{nativeMessageId}.xml");

            var dir = Path.GetDirectoryName(bodyPath);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            File.WriteAllBytes(bodyPath, operation.Message.Body);

            var messageContents = new List <string>
            {
                bodyPath,
                HeaderSerializer.Serialize(operation.Message.Headers)
            };

            var messagePath = Path.Combine(basePath, $"{nativeMessageId}.txt");

            // write to temp file first so an atomic move can be done
            // this avoids the file being locked when the receiver tries to process it
            var tempFile = Path.GetTempFileName();
            File.WriteAllLines(tempFile, messageContents);
            File.Move(tempFile, messagePath);
        }

        return(TaskEx.CompletedTask);
    }
Esempio n. 3
0
 public Task Init(Func <MessageContext, Task> onMessage, Func <ErrorContext, Task <ErrorHandleResult> > onError, CriticalError criticalError, PushSettings settings)
 {
     this.onError   = onError;
     pipeline       = onMessage;
     path           = BaseDirectoryBuilder.BuildBasePath(settings.InputQueue);
     purgeOnStartup = settings.PurgeOnStartup;
     return(Task.CompletedTask);
 }
    static void CreateQueueDirectory(string address)
    {
        var fullPath     = BaseDirectoryBuilder.BuildBasePath(address);
        var commitedPath = Path.Combine(fullPath, ".committed");

        Directory.CreateDirectory(commitedPath);
        var bodiesPath = Path.Combine(fullPath, ".bodies");

        Directory.CreateDirectory(bodiesPath);
    }
    public Task Dispatch(TransportOperations outgoingMessages, ContextBag context)
    {
        foreach (UnicastTransportOperation transportOperation in outgoingMessages.UnicastTransportOperations)
        {
            string basePath        = BaseDirectoryBuilder.BuildBasePath(transportOperation.Destination);
            string nativeMessageId = Guid.NewGuid().ToString();
            string bodyPath        = Path.Combine(basePath, ".bodies", nativeMessageId) + ".xml";

            var dir = Path.GetDirectoryName(bodyPath);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            File.WriteAllBytes(bodyPath, transportOperation.Message.Body);

            List <string> messageContents = new List <string>
            {
                bodyPath,
                HeaderSerializer.Serialize(transportOperation.Message.Headers)
            };

            DirectoryBasedTransaction transaction;

            string messagePath = Path.Combine(basePath, nativeMessageId) + ".txt";

            if (transportOperation.RequiredDispatchConsistency != DispatchConsistency.Isolated &&
                context.TryGet(out transaction))
            {
                transaction.Enlist(messagePath, messageContents);
            }
            else
            {
                string tempFile = Path.GetTempFileName();

                //write to temp file first so an atomic move can be done
                //this avoids the file being locked when the receiver tries to process it
                File.WriteAllLines(tempFile, messageContents);
                File.Move(tempFile, messagePath);
            }
        }

        return(TaskEx.CompletedTask);
    }