root/lang/perl/Mvalve/trunk/lib/Mvalve.pm @ 15848

Revision 15848, 3.5 kB (checked in by daisuke, 5 years ago)

version++

Line 
1# $Id$
2
3package Mvalve;
4use Mvalve::Const;
5use Mvalve::Types;
6use Mvalve::Message;
7use Mvalve::Reader;
8use Mvalve::Throttler;
9use Mvalve::Writer;
10use Time::HiRes();
11
12our $VERSION   = '0.00009';
13our $AUTHORITY = "cpan:DMAKI";
14
15sub trace { print STDERR "MVALVE: @_\n" }
16
171;
18
19__END__
20
21=head1 NAME
22
23Mvalve - Generic Q4M Powered Message Pipe
24
25=head1 SYNOPSIS
26
27  my $writer = Mvalve::Writer->new(
28    queue => {
29      args => {
30        connect_info => [ 'dbi:mysql:dbname=...', ..., ... ]
31      }
32    }
33  );
34
35  my $reader = Mvalve::Reader->new(
36    state => {
37      args => {
38      }
39    },
40    queue => {
41      module => "...",
42      args => {
43        connect_info => [ ... ]
44      }
45    },
46    throttler => {
47      args => {
48        max_items => $max,
49        interval  => $interval,
50        cache     => {
51          data => [ ... ]
52        }
53      }
54    }
55  );
56
57  $writer->insert( Mvalve::Message->new(...) );
58
59  while ( 1 ) {
60    my $message = $reader->next;
61    if ($message) {
62      # do whatever
63    }
64  }
65
66=head1 DESCRIPTION
67
68Mvalve stands for "Messave Valve". It is a frontend for Q4M powered set of
69queues, acting as a single pipe.
70
71Mvalve contains a reader and a writer. It's constructed like this because
72typically Mvalve operations are done in separate, read-only or write-only
73processes, so you don't need both to do the job.
74
75All throttling is done at the reader side, so the only thing that the writer
76needs is the information about the queue:
77
78  Mvalve::Writer->new( queue => $queue_object );
79  # or
80  Mvalve::Writer->new(
81    queue => {
82      args => {
83        connect_info => [ 'dbi:mysql:dbname=...', ..., ... ]
84      }
85    }
86  );
87
88The reader needs a bit more information:
89
90  Mvalve::Reader->new(
91    queue => $queue_object,
92    throttler => $throttler_object, # optional - default will be provided
93    state => $state_object,         # optional - default will be provided
94  );
95  # or
96  Mvalve::Reader->new(
97    queue => {
98      module => "Q4M",
99      args => {
100        connect_info => [ 'dbi:mysql:dbname=...', ..., ... ]
101      }
102    },
103    throttler => {
104      module => "Data::Valve",
105      args => {
106        max_items => 1,
107        interval  => 10,
108        store     => {
109          module => "Memcached",
110          args => {
111            servers => [ ... ]
112          }
113        }
114      }
115    },
116    state => {
117      module => "Memcached",
118      args => {
119       servers => [ ... ]
120      }
121    }
122  );
123
124=head1 SETUP
125
126You need to have installed mysql 5.1 or later and q4m. You can grab
127them at:
128
129  http://dev.mysql.com/
130  http://q4m.31tools.com/
131
132Once you have a q4m-enabled mysql running, you need to create these q4m
133enabled tables in your mysql database.
134
135  CREATE TABLE q_emerg (
136     destination VARCHAR(40) NOT NULL,
137     message     BLOB NOT NULL
138  ) ENGINE=QUEUE DEFAULT CHARSET=utf8
139 
140  CREATE TABLE q_timed (
141     destination VARCHAR(40) NOT NULL,
142     ready       BIGINT NOT NULL,
143     message     BLOB NOT NULL
144  ) ENGINE=QUEUE DEFAULT CHARSET=utf8
145 
146  CREATE TABLE q_incoming (
147     destination VARCHAR(40) NOT NULL,
148     message     BLOB NOT NULL
149  ) ENGINE=QUEUE DEFAULT CHARSET=utf8
150
151You also need to setup a memcached compatible distributed cache/storage.
152This will be used to share certain key data across multiple instances
153of Mvalve.
154
155=head1 METHODS
156 
157=head2 trace
158
159This is for debugging only
160
161=head1 AUTHORS
162
163Daisuke Maki C<< <daisuke@endeworks.jp> >>
164
165Taro Funaki C<< <t@33rpm.jp> >>
166
167=head1 LICENSE
168
169This program is free software; you can redistribute it and/or modify it
170under the same terms as Perl itself.
171
172See http://www.perl.com/perl/misc/Artistic.html
173
174=cut
175
Note: See TracBrowser for help on using the browser.