Dequeue

To dequeue to file, the queues from which we want to dequeue to file must be classified as Outbox or Passthrough. Then we must configure MessageRoutes which specify where on the filesystem the files should be written. Note that there is also one dequeue-related property stored in the InstanceConfig:

<DequeueConfig>
<GlobalTempDir>/sample/DequeueTmp</GlobalTempDir>
</DequeueConfig>

GlobalTempDir is a temporary location where the payload will be streamed during dequeue; once that is done, it will be renamed to the proper DestinationDir. This ensures that a client won’t try to pickup the file during transfer. In order for this to work properly, GlobalTempDir must be on the same filesystem as the DestinationDir. You can override the GlobalTempDir for a particular DequeueConfig using TempDir)

A MessageRoute with a MessageDestination of DestinationType File is used to configure the final destination for a message being dequeued to file.

<MessageDestination>
<ValueChainId>9123</ValueChainId>
<Name>outbox/Orders/error</Name>
<DestinationType>File</DestinationType>
<Config>{destinationDir: '${SharedFileSystemRoot}/SimpleOrder.response', fileNamePattern: '%{Timestamp}.%{FileName}.error', useXferExtension:'true'}</Config>
</MessageDestination>
<MessageRoute>
<ValueChainId>9123</ValueChainId>
<OriginQueueName>outbox/Orders/error</OriginQueueName>
<DestinationName>outbox/Orders/error</DestinationName>
</MessageRoute>

The Config is a JSON object containing:

  • destinationDir (required) – the directory into which the file should be placed. You can reference Platform InstanceConfig substitution parameters using ${} syntax within these properties.

  • tempDir (optional) – if you want to specify a temp directory other than the Dequeue GlobalTempDir specified in the InstanceConfig.

  • fileNamePattern (optional) - by default, a new unique file name will automatically be given to the file created. fileNamePattern is an optional file name substitution pattern used when dequeuing messages. Use the following substitution parameter syntax:

    • %{FileName} will use the original file name

    • %{Timestamp} will use the current timestamp (plus some additional values to distinguish the origin server, ensuring it is globally unique within a NEO cluster)

    • %{currentDate:yyyy-MM-dd_HH_mm_ss} will render the current time using a java SimpleDateFormat pattern.

    • EXAMPLE: %{FileName}.foo.%{Timestamp} applied to test.csv will result in test.csv.foo.20091103161638637

  • fileNamer (optional) - as an alternative to fileNamePattern, you can provide a fileNamer. Here you should give a groovy expression which evaluates to the desired value of the file name. The com.onenetwork.platform.integ.msg.Message being dequeued will be bound under the name msg so you can use things like interface name, client file name, etc. to help you generate the final file name. Also bound is the resolvedFileName which is derived using fileNamePattern which developer can return as a fallback.

    Example:

    fileNamer: 'msg.getOutboundInterface() + "." + System.currentTimeMillis() + ".csv"'

    or

    fileNamer: 'if ("ZBKS.BookLoad".equals(msg.getOutboundInterface())) { msg.getOutboundInterface() + "." + System.currentTimeMillis() + ".csv" } else { resolvedFileName }'

  • useXferExtension (optional) - set this to true if you want to use .xfer extension to write the destination file and then rename it to fileNamePattern after write is complete. This will ensure that processes polling for the "real" extension (like .csv or .xml or .zip) will not pick up the file before it is fully written.