The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

POE::Component::MessageQueue::Storage::Complex -- A configurable storage engine that keeps a front-store (something fast) and a back-store (something persistent), allowing you to specify a timeout and an action to be taken when messages in the front-store expire.

SYNOPSIS

  use POE;
  use POE::Component::MessageQueue;
  use POE::Component::MessageQueue::Storage::Complex;
  use strict;

  POE::Component::MessageQueue->new({
    storage => POE::Component::MessageQueue::Storage::Complex->new({
      timeout      => 4,
      throttle_max => 2,

      front_store => POE::Component::MessageQueue::Storage::Memory->new(),
      # Or, an alternative memory store is available!
      #front_store => POE::Component::MessageQueue::Storage::BigMemory->new(),

      back_store => POE::Component::MessageQueue::Storage::Throttled->new({
        storage => My::Persistent::But::Slow::Datastore->new()

        # Examples include:
        #storage => POE::Component::MessageQueue::Storage::DBI->new({ ... });
        #storage => POE::Component::MessageQueue::Storage::FileSystem->new({ ... });
      }),

      # Optional: Action to perform on after timeout.  By default moves all
      # persistent messages into the backstore.
      expire_messages => sub {
        my $arrayref_of_message_ids = shift;
        do_something($arrayref_of_message_ids);
      },
    })
  });

POE::Kernel->run(); exit;

DESCRIPTION

The idea of having a front store (something quick) and a back store (something persistent) is common and recommended, so this class exists as a helper to implementing that pattern. It wraps any front and back store that you specify, a timeout that you specify, and tells you when messages expire.

CONSTRUCTOR PARAMETERS

timeout => SCALAR

The number of seconds after a message enters the front-store before it expires. After this time, if the message hasn't been removed, it will be passed to expire_messages.

expire_messages => CODEREF

A function of one argument (an arrayref of message ids) that does something with expired messages. The default action is to delete them from the front store and store them in the back-store, but you can override that here.

front_store => SCALAR

Takes a reference to a storage engine to use as the front store.

Currently, only the following storage engines are capable to be front stores:

Expect this to change in future versions.

back_store => SCALAR

Takes a reference to a storage engine to use as the back store.

Using POE::Component::MessageQueue::Storage::Throttled to wrap your main storage engine is highly recommended for the reasons explained in its specific documentation.

SEE ALSO

POE::Component::MessageQueue::Storage::Complex::Default - The most common case. Based on this storage engine.

External references:

POE::Component::MessageQueue, POE::Component::MessageQueue::Storage, DBI, DBD::SQLite

Other storage engines:

POE::Component::MessageQueue::Storage::Default, POE::Component::MessageQueue::Storage::Memory, POE::Component::MessageQueue::Storage::BigMemory, POE::Component::MessageQueue::Storage::FileSystem, POE::Component::MessageQueue::Storage::DBI, POE::Component::MessageQueue::Storage::Generic, POE::Component::MessageQueue::Storage::Generic::DBI, POE::Component::MessageQueue::Storage::Throttled POE::Component::MessageQueue::Storage::Default