€cdocutils.nodes document q)q}q(U nametypesq}q(Xgetting a queue (by name)qNXdeleting messages and queuesqNXcreating a queueqNX writing messages (custom format)q NXsqs_tutq ˆXreading message attributesq NXlisting all queuesq NXcreating a connectionq NXreading messagesqNXadditional informationqNXwriting messagesqNX'an introduction to boto's sqs interfaceqNuUsubstitution_defsq}qUparse_messagesq]qcdocutils.nodes system_message q)q}q(U rawsourceqUUparentqcdocutils.nodes section q)q}q(hUhh)q}q(hUhhUsourceq X=/Users/kyleknap/Documents/GitHub/boto/docs/source/sqs_tut.rstq!Uexpect_referenced_by_nameq"}q#h cdocutils.nodes target q$)q%}q&(hX .. _sqs_tut:hhh h!Utagnameq'Utargetq(U attributesq)}q*(Uidsq+]Ubackrefsq,]Udupnamesq-]Uclassesq.]Unamesq/]Urefidq0Usqs-tutq1uUlineq2KUdocumentq3hUchildrenq4]ubsh'Usectionq5h)}q6(h-]h.]h,]h+]q7(U'an-introduction-to-boto-s-sqs-interfaceq8h1eh/]q9(hh euh2Kh3hUexpect_referenced_by_idq:}q;h1h%sh4]q<(cdocutils.nodes title q=)q>}q?(hX'An Introduction to boto's SQS interfaceq@hhh h!h'UtitleqAh)}qB(h-]h.]h,]h+]h/]uh2Kh3hh4]qCcdocutils.nodes Text qDX'An Introduction to boto's SQS interfaceqE…qF}qG(hh@hh>ubaubcdocutils.nodes paragraph qH)qI}qJ(hX­This tutorial focuses on the boto interface to the Simple Queue Service from Amazon Web Services. This tutorial assumes that you have boto already downloaded and installed.qKhhh h!h'U paragraphqLh)}qM(h-]h.]h,]h+]h/]uh2Kh3hh4]qNhDX­This tutorial focuses on the boto interface to the Simple Queue Service from Amazon Web Services. This tutorial assumes that you have boto already downloaded and installed.qO…qP}qQ(hhKhhIubaubh)qR}qS(hUhhh h!h'h5h)}qT(h-]h.]h,]h+]qUUcreating-a-connectionqVah/]qWh auh2K h3hh4]qX(h=)qY}qZ(hXCreating a Connectionq[hhRh h!h'hAh)}q\(h-]h.]h,]h+]h/]uh2K h3hh4]q]hDXCreating a Connectionq^…q_}q`(hh[hhYubaubhH)qa}qb(hX~The first step in accessing SQS is to create a connection to the service. The recommended method of doing this is as follows::hhRh h!h'hLh)}qc(h-]h.]h,]h+]h/]uh2K h3hh4]qdhDX}The first step in accessing SQS is to create a connection to the service. The recommended method of doing this is as follows:qe…qf}qg(hX}The first step in accessing SQS is to create a connection to the service. The recommended method of doing this is as follows:hhaubaubcdocutils.nodes literal_block qh)qi}qj(hX¯>>> import boto.sqs >>> conn = boto.sqs.connect_to_region( ... "us-west-2", ... aws_access_key_id='', ... aws_secret_access_key='')hhRh h!h'U literal_blockqkh)}ql(U xml:spaceqmUpreserveqnh+]h,]h-]h.]h/]uh2Kh3hh4]qohDX¯>>> import boto.sqs >>> conn = boto.sqs.connect_to_region( ... "us-west-2", ... aws_access_key_id='', ... aws_secret_access_key='')qp…qq}qr(hUhhiubaubhH)qs}qt(hX<At this point the variable conn will point to an SQSConnection object in the US-WEST-2 region. Bear in mind that just as any other AWS service, SQS is region-specific. In this example, the AWS access key and AWS secret key are passed in to the method explicitly. Alternatively, you can set the environment variables:quhhRh h!h'hLh)}qv(h-]h.]h,]h+]h/]uh2Kh3hh4]qwhDX<At this point the variable conn will point to an SQSConnection object in the US-WEST-2 region. Bear in mind that just as any other AWS service, SQS is region-specific. In this example, the AWS access key and AWS secret key are passed in to the method explicitly. Alternatively, you can set the environment variables:qx…qy}qz(hhuhhsubaubcdocutils.nodes bullet_list q{)q|}q}(hUhhRh h!h'U bullet_listq~h)}q(Ubulletq€X*h+]h,]h-]h.]h/]uh2Kh3hh4]q(cdocutils.nodes list_item q‚)qƒ}q„(hX.``AWS_ACCESS_KEY_ID`` - Your AWS Access Key IDq…hh|h h!h'U list_itemq†h)}q‡(h-]h.]h,]h+]h/]uh2Nh3hh4]qˆhH)q‰}qŠ(hh…hhƒh h!h'hLh)}q‹(h-]h.]h,]h+]h/]uh2Kh4]qŒ(cdocutils.nodes literal q)qŽ}q(hX``AWS_ACCESS_KEY_ID``h)}q(h-]h.]h,]h+]h/]uhh‰h4]q‘hDXAWS_ACCESS_KEY_IDq’…q“}q”(hUhhŽubah'Uliteralq•ubhDX - Your AWS Access Key IDq–…q—}q˜(hX - Your AWS Access Key IDhh‰ubeubaubh‚)q™}qš(hX7``AWS_SECRET_ACCESS_KEY`` - Your AWS Secret Access Key hh|h h!h'h†h)}q›(h-]h.]h,]h+]h/]uh2Nh3hh4]qœhH)q}qž(hX6``AWS_SECRET_ACCESS_KEY`` - Your AWS Secret Access Keyhh™h h!h'hLh)}qŸ(h-]h.]h,]h+]h/]uh2Kh4]q (h)q¡}q¢(hX``AWS_SECRET_ACCESS_KEY``h)}q£(h-]h.]h,]h+]h/]uhhh4]q¤hDXAWS_SECRET_ACCESS_KEYq¥…q¦}q§(hUhh¡ubah'h•ubhDX - Your AWS Secret Access Keyq¨…q©}qª(hX - Your AWS Secret Access KeyhhubeubaubeubhH)q«}q¬(hXand then simply call::q­hhRh h!h'hLh)}q®(h-]h.]h,]h+]h/]uh2Kh3hh4]q¯hDXand then simply call:q°…q±}q²(hXand then simply call:hh«ubaubhh)q³}q´(hXF>>> import boto.sqs >>> conn = boto.sqs.connect_to_region("us-west-2")hhRh h!h'hkh)}qµ(hmhnh+]h,]h-]h.]h/]uh2K!h3hh4]q¶hDXF>>> import boto.sqs >>> conn = boto.sqs.connect_to_region("us-west-2")q·…q¸}q¹(hUhh³ubaubhH)qº}q»(hXwIn either case, conn will point to an SQSConnection object which we will use throughout the remainder of this tutorial.q¼hhRh h!h'hLh)}q½(h-]h.]h,]h+]h/]uh2K$h3hh4]q¾hDXwIn either case, conn will point to an SQSConnection object which we will use throughout the remainder of this tutorial.q¿…qÀ}qÁ(hh¼hhºubaubeubh)qÂ}qÃ(hUhhh h!h'h5h)}qÄ(h-]h.]h,]h+]qÅUcreating-a-queueqÆah/]qÇhauh2K(h3hh4]qÈ(h=)qÉ}qÊ(hXCreating a QueueqËhhÂh h!h'hAh)}qÌ(h-]h.]h,]h+]h/]uh2K(h3hh4]qÍhDXCreating a QueueqÎ…qÏ}qÐ(hhËhhÉubaubhH)qÑ}qÒ(hX—Once you have a connection established with SQS, you will probably want to create a queue. In its simplest form, that can be accomplished as follows::hhÂh h!h'hLh)}qÓ(h-]h.]h,]h+]h/]uh2K)h3hh4]qÔhDX–Once you have a connection established with SQS, you will probably want to create a queue. In its simplest form, that can be accomplished as follows:qÕ…qÖ}q×(hX–Once you have a connection established with SQS, you will probably want to create a queue. In its simplest form, that can be accomplished as follows:hhÑubaubhh)qØ}qÙ(hX$>>> q = conn.create_queue('myqueue')hhÂh h!h'hkh)}qÚ(hmhnh+]h,]h-]h.]h/]uh2K,h3hh4]qÛhDX$>>> q = conn.create_queue('myqueue')qÜ…qÝ}qÞ(hUhhØubaubhH)qß}qà(hX@The create_queue method will create (and return) the requested queue if it does not exist or will return the existing queue if it does. There is an optional parameter to create_queue called visibility_timeout. This basically controls how long a message will remain invisible to other queue readers once it has been read (see SQS documentation for more detailed explanation). If this is not explicitly specified the queue will be created with whatever default value SQS provides (currently 30 seconds). If you would like to specify another value, you could do so like this::hhÂh h!h'hLh)}qá(h-]h.]h,]h+]h/]uh2K.h3hh4]qâhDX?The create_queue method will create (and return) the requested queue if it does not exist or will return the existing queue if it does. There is an optional parameter to create_queue called visibility_timeout. This basically controls how long a message will remain invisible to other queue readers once it has been read (see SQS documentation for more detailed explanation). If this is not explicitly specified the queue will be created with whatever default value SQS provides (currently 30 seconds). If you would like to specify another value, you could do so like this:qã…qä}qå(hX?The create_queue method will create (and return) the requested queue if it does not exist or will return the existing queue if it does. There is an optional parameter to create_queue called visibility_timeout. This basically controls how long a message will remain invisible to other queue readers once it has been read (see SQS documentation for more detailed explanation). If this is not explicitly specified the queue will be created with whatever default value SQS provides (currently 30 seconds). If you would like to specify another value, you could do so like this:hhßubaubhh)qæ}qç(hX)>>> q = conn.create_queue('myqueue', 120)hhÂh h!h'hkh)}qè(hmhnh+]h,]h-]h.]h/]uh2K7h3hh4]qéhDX)>>> q = conn.create_queue('myqueue', 120)qê…që}qì(hUhhæubaubhH)qí}qî(hXThis would establish a default visibility timeout for this queue of 120 seconds. As you will see later on, this default value for the queue can also be overridden each time a message is read from the queue. If you want to check what the default visibility timeout is for a queue::hhÂh h!h'hLh)}qï(h-]h.]h,]h+]h/]uh2K9h3hh4]qðhDXThis would establish a default visibility timeout for this queue of 120 seconds. As you will see later on, this default value for the queue can also be overridden each time a message is read from the queue. If you want to check what the default visibility timeout is for a queue:qñ…qò}qó(hXThis would establish a default visibility timeout for this queue of 120 seconds. As you will see later on, this default value for the queue can also be overridden each time a message is read from the queue. If you want to check what the default visibility timeout is for a queue:hhíubaubhh)qô}qõ(hX>>> q.get_timeout() 30hhÂh h!h'hkh)}qö(hmhnh+]h,]h-]h.]h/]uh2K>h3hh4]q÷hDX>>> q.get_timeout() 30qø…qù}qú(hUhhôubaubeubh)qû}qü(hUhhh h!h'h5h)}qý(h-]h.]h,]h+]qþUlisting-all-queuesqÿah/]rh auh2KBh3hh4]r(h=)r}r(hXListing all Queuesrhhûh h!h'hAh)}r(h-]h.]h,]h+]h/]uh2KBh3hh4]rhDXListing all Queuesr…r}r (hjhjubaubhH)r }r (hXITo retrieve a list of the queues for your account in the current region::r hhûh h!h'hLh)}r (h-]h.]h,]h+]h/]uh2KDh3hh4]rhDXHTo retrieve a list of the queues for your account in the current region:r…r}r(hXHTo retrieve a list of the queues for your account in the current region:hj ubaubhh)r}r(hXà>>> conn.get_all_queues() [ Queue(https://queue.amazonaws.com/411358162645/myqueue), Queue(https://queue.amazonaws.com/411358162645/another_queue), Queue(https://queue.amazonaws.com/411358162645/another_queue2) ]hhûh h!h'hkh)}r(hmhnh+]h,]h-]h.]h/]uh2KFh3hh4]rhDXà>>> conn.get_all_queues() [ Queue(https://queue.amazonaws.com/411358162645/myqueue), Queue(https://queue.amazonaws.com/411358162645/another_queue), Queue(https://queue.amazonaws.com/411358162645/another_queue2) ]r…r}r(hUhjubaubhH)r}r(hX±This will leave you with a list of all of your :py:class:`boto.sqs.queue.Queue` instances. Alternatively, if you wanted to only list the queues that started with ``'another'``::hhûh h!h'hLh)}r(h-]h.]h,]h+]h/]uh2KMh3hh4]r(hDX/This will leave you with a list of all of your r…r}r(hX/This will leave you with a list of all of your hjubcsphinx.addnodes pending_xref r )r!}r"(hX :py:class:`boto.sqs.queue.Queue`r#hjh h!h'U pending_xrefr$h)}r%(UreftypeXclassUrefwarnr&‰U reftargetr'Xboto.sqs.queue.QueueU refdomainXpyr(h+]h,]U refexplicit‰h-]h.]h/]Urefdocr)Xsqs_tutr*Upy:classr+NU py:moduler,Nuh2KMh4]r-h)r.}r/(hj#h)}r0(h-]h.]r1(Uxrefr2j(Xpy-classr3eh,]h+]h/]uhj!h4]r4hDXboto.sqs.queue.Queuer5…r6}r7(hUhj.ubah'h•ubaubhDXS instances. Alternatively, if you wanted to only list the queues that started with r8…r9}r:(hXS instances. Alternatively, if you wanted to only list the queues that started with hjubh)r;}r<(hX ``'another'``h)}r=(h-]h.]h,]h+]h/]uhjh4]r>hDX 'another'r?…r@}rA(hUhj;ubah'h•ubhDX:…rB}rC(hX:hjubeubhh)rD}rE(hX³>>> conn.get_all_queues(prefix='another') [ Queue(https://queue.amazonaws.com/411358162645/another_queue), Queue(https://queue.amazonaws.com/411358162645/another_queue2) ]hhûh h!h'hkh)}rF(hmhnh+]h,]h-]h.]h/]uh2KQh3hh4]rGhDX³>>> conn.get_all_queues(prefix='another') [ Queue(https://queue.amazonaws.com/411358162645/another_queue), Queue(https://queue.amazonaws.com/411358162645/another_queue2) ]rH…rI}rJ(hUhjDubaubeubh)rK}rL(hUhhh h!h'h5h)}rM(h-]h.]h,]h+]rNUgetting-a-queue-by-namerOah/]rPhauh2KXh3hh4]rQ(h=)rR}rS(hXGetting a Queue (by name)rThjKh h!h'hAh)}rU(h-]h.]h,]h+]h/]uh2KXh3hh4]rVhDXGetting a Queue (by name)rW…rX}rY(hjThjRubaubhH)rZ}r[(hX€If you wish to explicitly retrieve an existing queue and the name of the queue is known, you can retrieve the queue as follows::hjKh h!h'hLh)}r\(h-]h.]h,]h+]h/]uh2KYh3hh4]r]hDXIf you wish to explicitly retrieve an existing queue and the name of the queue is known, you can retrieve the queue as follows:r^…r_}r`(hXIf you wish to explicitly retrieve an existing queue and the name of the queue is known, you can retrieve the queue as follows:hjZubaubhh)ra}rb(hX`>>> my_queue = conn.get_queue('myqueue') Queue(https://queue.amazonaws.com/411358162645/myqueue)hjKh h!h'hkh)}rc(hmhnh+]h,]h-]h.]h/]uh2K\h3hh4]rdhDX`>>> my_queue = conn.get_queue('myqueue') Queue(https://queue.amazonaws.com/411358162645/myqueue)re…rf}rg(hUhjaubaubhH)rh}ri(hXnThis leaves you with a single :py:class:`boto.sqs.queue.Queue`, which abstracts the SQS Queue named 'myqueue'.hjKh h!h'hLh)}rj(h-]h.]h,]h+]h/]uh2K_h3hh4]rk(hDXThis leaves you with a single rl…rm}rn(hXThis leaves you with a single hjhubj )ro}rp(hX :py:class:`boto.sqs.queue.Queue`rqhjhh h!h'j$h)}rr(UreftypeXclassj&‰j'Xboto.sqs.queue.QueueU refdomainXpyrsh+]h,]U refexplicit‰h-]h.]h/]j)j*j+Nj,Nuh2K_h4]rth)ru}rv(hjqh)}rw(h-]h.]rx(j2jsXpy-classryeh,]h+]h/]uhjoh4]rzhDXboto.sqs.queue.Queuer{…r|}r}(hUhjuubah'h•ubaubhDX0, which abstracts the SQS Queue named 'myqueue'.r~…r}r€(hX0, which abstracts the SQS Queue named 'myqueue'.hjhubeubeubh)r}r‚(hUhhh h!h'h5h)}rƒ(h-]h.]h,]h+]r„Uwriting-messagesr…ah/]r†hauh2Kch3hh4]r‡(h=)rˆ}r‰(hXWriting MessagesrŠhjh h!h'hAh)}r‹(h-]h.]h,]h+]h/]uh2Kch3hh4]rŒhDXWriting Messagesr…rŽ}r(hjŠhjˆubaubhH)r}r‘(hXOnce you have a queue setup, presumably you will want to write some messages to it. SQS doesn't care what kind of information you store in your messages or what format you use to store it. As long as the amount of data per message is less than or equal to 256Kb, SQS won't complain.r’hjh h!h'hLh)}r“(h-]h.]h,]h+]h/]uh2Kdh3hh4]r”hDXOnce you have a queue setup, presumably you will want to write some messages to it. SQS doesn't care what kind of information you store in your messages or what format you use to store it. As long as the amount of data per message is less than or equal to 256Kb, SQS won't complain.r•…r–}r—(hj’hjubaubhH)r˜}r™(hX.So, first we need to create a Message object::ršhjh h!h'hLh)}r›(h-]h.]h,]h+]h/]uh2Kih3hh4]rœhDX-So, first we need to create a Message object:r…rž}rŸ(hX-So, first we need to create a Message object:hj˜ubaubhh)r }r¡(hXu>>> from boto.sqs.message import Message >>> m = Message() >>> m.set_body('This is my first message.') >>> q.write(m)hjh h!h'hkh)}r¢(hmhnh+]h,]h-]h.]h/]uh2Kkh3hh4]r£hDXu>>> from boto.sqs.message import Message >>> m = Message() >>> m.set_body('This is my first message.') >>> q.write(m)r¤…r¥}r¦(hUhj ubaubhH)r§}r¨(hX¾The write method will return the ``Message`` object. The ``id`` and ``md5`` attribute of the ``Message`` object will be updated with the values of the message that was written to the queue.hjh h!h'hLh)}r©(h-]h.]h,]h+]h/]uh2Kph3hh4]rª(hDX!The write method will return the r«…r¬}r­(hX!The write method will return the hj§ubh)r®}r¯(hX ``Message``h)}r°(h-]h.]h,]h+]h/]uhj§h4]r±hDXMessager²…r³}r´(hUhj®ubah'h•ubhDX object. The rµ…r¶}r·(hX object. The hj§ubh)r¸}r¹(hX``id``h)}rº(h-]h.]h,]h+]h/]uhj§h4]r»hDXidr¼…r½}r¾(hUhj¸ubah'h•ubhDX and r¿…rÀ}rÁ(hX and hj§ubh)rÂ}rÃ(hX``md5``h)}rÄ(h-]h.]h,]h+]h/]uhj§h4]rÅhDXmd5rÆ…rÇ}rÈ(hUhjÂubah'h•ubhDX attribute of the rÉ…rÊ}rË(hX attribute of the hj§ubh)rÌ}rÍ(hX ``Message``h)}rÎ(h-]h.]h,]h+]h/]uhj§h4]rÏhDXMessagerÐ…rÑ}rÒ(hUhjÌubah'h•ubhDXU object will be updated with the values of the message that was written to the queue.rÓ…rÔ}rÕ(hXU object will be updated with the values of the message that was written to the queue.hj§ubeubhH)rÖ}r×(hXlArbitrary message attributes can be defined by setting a simple dictionary of values on the message object::hjh h!h'hLh)}rØ(h-]h.]h,]h+]h/]uh2Kth3hh4]rÙhDXkArbitrary message attributes can be defined by setting a simple dictionary of values on the message object:rÚ…rÛ}rÜ(hXkArbitrary message attributes can be defined by setting a simple dictionary of values on the message object:hjÖubaubhh)rÝ}rÞ(hX>>> m = Message() >>> m.message_attributes = { ... "name1": { ... "data_type": "String", ... "string_value": "I am a string" ... }, ... "name2": { ... "data_type": "Number", ... "string_value": "12" ... } ... }hjh h!h'hkh)}rß(hmhnh+]h,]h-]h.]h/]uh2Kwh3hh4]ràhDX>>> m = Message() >>> m.message_attributes = { ... "name1": { ... "data_type": "String", ... "string_value": "I am a string" ... }, ... "name2": { ... "data_type": "Number", ... "string_value": "12" ... } ... }rá…râ}rã(hUhjÝubaubhH)rä}rå(hX¾Note that by default, these arbitrary attributes are not returned when you request messages from a queue. Instead, you must request them via the ``message_attributes`` parameter (see below).hjh h!h'hLh)}ræ(h-]h.]h,]h+]h/]uh2Kƒh3hh4]rç(hDX‘Note that by default, these arbitrary attributes are not returned when you request messages from a queue. Instead, you must request them via the rè…ré}rê(hX‘Note that by default, these arbitrary attributes are not returned when you request messages from a queue. Instead, you must request them via the hjäubh)rë}rì(hX``message_attributes``h)}rí(h-]h.]h,]h+]h/]uhjäh4]rîhDXmessage_attributesrï…rð}rñ(hUhjëubah'h•ubhDX parameter (see below).rò…ró}rô(hX parameter (see below).hjäubeubhH)rõ}rö(hXJIf the message cannot be written an ``SQSError`` exception will be raised.r÷hjh h!h'hLh)}rø(h-]h.]h,]h+]h/]uh2K‡h3hh4]rù(hDX$If the message cannot be written an rú…rû}rü(hX$If the message cannot be written an hjõubh)rý}rþ(hX ``SQSError``h)}rÿ(h-]h.]h,]h+]h/]uhjõh4]rhDXSQSErrorr…r}r(hUhjýubah'h•ubhDX exception will be raised.r…r}r(hX exception will be raised.hjõubeubeubh)r}r(hUhhh h!h'h5h)}r (h-]h.]h,]h+]r Uwriting-messages-custom-formatr ah/]r h auh2KŠh3hh4]r (h=)r}r(hX Writing Messages (Custom Format)rhjh h!h'hAh)}r(h-]h.]h,]h+]h/]uh2KŠh3hh4]rhDX Writing Messages (Custom Format)r…r}r(hjhjubaubhH)r}r(hXyThe technique above will work only if you use boto's default Message payload format; however, you may have a lot of specific requirements around the format of the message data. For example, you may want to store one big string or you might want to store something that looks more like RFC822 messages or you might want to store a binary payload such as pickled Python objects.rhjh h!h'hLh)}r(h-]h.]h,]h+]h/]uh2K‹h3hh4]rhDXyThe technique above will work only if you use boto's default Message payload format; however, you may have a lot of specific requirements around the format of the message data. For example, you may want to store one big string or you might want to store something that looks more like RFC822 messages or you might want to store a binary payload such as pickled Python objects.r…r}r(hjhjubaubhH)r}r(hXfThe way boto deals with this issue is to define a simple Message object that treats the message data as one big string which you can set and get. If that Message object meets your needs, you're good to go. However, if you need to incorporate different behavior in your message or handle different types of data you can create your own Message class. You just need to register that class with the boto queue object so that it knows that, when you read a message from the queue, it should create one of your message objects rather than the default boto Message object. To register your message class, you would::hjh h!h'hLh)}r (h-]h.]h,]h+]h/]uh2K‘h3hh4]r!hDXeThe way boto deals with this issue is to define a simple Message object that treats the message data as one big string which you can set and get. If that Message object meets your needs, you're good to go. However, if you need to incorporate different behavior in your message or handle different types of data you can create your own Message class. You just need to register that class with the boto queue object so that it knows that, when you read a message from the queue, it should create one of your message objects rather than the default boto Message object. To register your message class, you would:r"…r#}r$(hXeThe way boto deals with this issue is to define a simple Message object that treats the message data as one big string which you can set and get. If that Message object meets your needs, you're good to go. However, if you need to incorporate different behavior in your message or handle different types of data you can create your own Message class. You just need to register that class with the boto queue object so that it knows that, when you read a message from the queue, it should create one of your message objects rather than the default boto Message object. To register your message class, you would:hjubaubhh)r%}r&(hX†>>> import MyMessage >>> q.set_message_class(MyMessage) >>> m = MyMessage() >>> m.set_body('This is my first message.') >>> q.write(m)hjh h!h'hkh)}r'(hmhnh+]h,]h-]h.]h/]uh2Kšh3hh4]r(hDX†>>> import MyMessage >>> q.set_message_class(MyMessage) >>> m = MyMessage() >>> m.set_body('This is my first message.') >>> q.write(m)r)…r*}r+(hUhj%ubaubhH)r,}r-(hXäwhere MyMessage is the class definition for your message class. Your message class should subclass the boto Message because there is a small bit of Python magic happening in the ``__setattr__`` method of the boto Message class.hjh h!h'hLh)}r.(h-]h.]h,]h+]h/]uh2K h3hh4]r/(hDX³where MyMessage is the class definition for your message class. Your message class should subclass the boto Message because there is a small bit of Python magic happening in the r0…r1}r2(hX³where MyMessage is the class definition for your message class. Your message class should subclass the boto Message because there is a small bit of Python magic happening in the hj,ubh)r3}r4(hX``__setattr__``h)}r5(h-]h.]h,]h+]h/]uhj,h4]r6hDX __setattr__r7…r8}r9(hUhj3ubah'h•ubhDX" method of the boto Message class.r:…r;}r<(hX" method of the boto Message class.hj,ubeubeubh)r=}r>(hUhhh h!h'h5h)}r?(h-]h.]h,]h+]r@Ureading-messagesrAah/]rBhauh2K¦h3hh4]rC(h=)rD}rE(hXReading MessagesrFhj=h h!h'hAh)}rG(h-]h.]h,]h+]h/]uh2K¦h3hh4]rHhDXReading MessagesrI…rJ}rK(hjFhjDubaubhH)rL}rM(hXZSo, now we have a message in our queue. How would we go about reading it? Here's one way:rNhj=h h!h'hLh)}rO(h-]h.]h,]h+]h/]uh2K¨h3hh4]rPhDXZSo, now we have a message in our queue. How would we go about reading it? Here's one way:rQ…rR}rS(hjNhjLubaubcdocutils.nodes doctest_block rT)rU}rV(hXb>>> rs = q.get_messages() >>> len(rs) 1 >>> m = rs[0] >>> m.get_body() u'This is my first message'hj=h h!h'U doctest_blockrWh)}rX(hmhnh+]h,]h-]h.]h/]uh2K°h3hh4]rYhDXb>>> rs = q.get_messages() >>> len(rs) 1 >>> m = rs[0] >>> m.get_body() u'This is my first message'rZ…r[}r\(hUhjUubaubhH)r]}r^(hX¿The get_messages method also returns a ResultSet object as described above. In addition to the special attributes that we already talked about the ResultSet object also contains any results returned by the request. To get at the results you can treat the ResultSet as a sequence object (e.g. a list). We can check the length (how many results) and access particular items within the list using the slice notation familiar to Python programmers.r_hj=h h!h'hLh)}r`(h-]h.]h,]h+]h/]uh2K²h3hh4]rahDX¿The get_messages method also returns a ResultSet object as described above. In addition to the special attributes that we already talked about the ResultSet object also contains any results returned by the request. To get at the results you can treat the ResultSet as a sequence object (e.g. a list). We can check the length (how many results) and access particular items within the list using the slice notation familiar to Python programmers.rb…rc}rd(hj_hj]ubaubhH)re}rf(hX_At this point, we have read the message from the queue and SQS will make sure that this message remains invisible to other readers of the queue until the visibility timeout period for the queue expires. If you delete the message before the timeout period expires then no one else will ever see the message again. However, if you don't delete it (maybe because your reader crashed or failed in some way, for example) it will magically reappear in my queue for someone else to read. If you aren't happy with the default visibility timeout defined for the queue, you can override it when you read a message:rghj=h h!h'hLh)}rh(h-]h.]h,]h+]h/]uh2Kºh3hh4]rihDX_At this point, we have read the message from the queue and SQS will make sure that this message remains invisible to other readers of the queue until the visibility timeout period for the queue expires. If you delete the message before the timeout period expires then no one else will ever see the message again. However, if you don't delete it (maybe because your reader crashed or failed in some way, for example) it will magically reappear in my queue for someone else to read. If you aren't happy with the default visibility timeout defined for the queue, you can override it when you read a message:rj…rk}rl(hjghjeubaubjT)rm}rn(hX)>>> q.get_messages(visibility_timeout=60)rohj=h h!h'jWh)}rp(hmhnh+]h,]h-]h.]h/]uh2KÃh3hh4]rqhDX)>>> q.get_messages(visibility_timeout=60)rr…rs}rt(hUhjmubaubhH)ru}rv(hX—This means that regardless of what the default visibility timeout is for the queue, this message will remain invisible to other readers for 60 seconds.rwhj=h h!h'hLh)}rx(h-]h.]h,]h+]h/]uh2KÅh3hh4]ryhDX—This means that regardless of what the default visibility timeout is for the queue, this message will remain invisible to other readers for 60 seconds.rz…r{}r|(hjwhjuubaubhH)r}}r~(hXThe get_messages method can also return more than a single message. By passing a num_messages parameter (defaults to 1) you can control the maximum number of messages that will be returned by the method. To show this feature off, first let's load up a few more messages.rhj=h h!h'hLh)}r€(h-]h.]h,]h+]h/]uh2KÉh3hh4]rhDXThe get_messages method can also return more than a single message. By passing a num_messages parameter (defaults to 1) you can control the maximum number of messages that will be returned by the method. To show this feature off, first let's load up a few more messages.r‚…rƒ}r„(hjhj}ubaubjT)r…}r†(hX™>>> for i in range(1, 11): ... m = Message() ... m.set_body('This is message %d' % i) ... q.write(m) ... >>> rs = q.get_messages(10) >>> len(rs) 10hj=h Nh'jWh)}r‡(hmhnh+]h,]h-]h.]h/]uh2Nh3hh4]rˆhDX™>>> for i in range(1, 11): ... m = Message() ... m.set_body('This is message %d' % i) ... q.write(m) ... >>> rs = q.get_messages(10) >>> len(rs) 10r‰…rŠ}r‹(hUhj…ubaubhH)rŒ}r(hXæDon't be alarmed if the length of the result set returned by the get_messages call is less than 10. Sometimes it takes some time for new messages to become visible in the queue. Give it a minute or two and they will all show up.rŽhj=h h!h'hLh)}r(h-]h.]h,]h+]h/]uh2K×h3hh4]rhDXæDon't be alarmed if the length of the result set returned by the get_messages call is less than 10. Sometimes it takes some time for new messages to become visible in the queue. Give it a minute or two and they will all show up.r‘…r’}r“(hjŽhjŒubaubhH)r”}r•(hXIf you want a slightly simpler way to read messages from a queue, you can use the read method. It will either return the message read or it will return None if no messages were available. You can also pass a visibility_timeout parameter to read, if you desire:r–hj=h h!h'hLh)}r—(h-]h.]h,]h+]h/]uh2KÛh3hh4]r˜hDXIf you want a slightly simpler way to read messages from a queue, you can use the read method. It will either return the message read or it will return None if no messages were available. You can also pass a visibility_timeout parameter to read, if you desire:r™…rš}r›(hj–hj”ubaubjT)rœ}r(hX?>>> m = q.read(60) >>> m.get_body() u'This is my first message'hj=h h!h'jWh)}rž(hmhnh+]h,]h-]h.]h/]uh2Kâh3hh4]rŸhDX?>>> m = q.read(60) >>> m.get_body() u'This is my first message'r …r¡}r¢(hUhjœubaubeubhh)r£}r¤(hUhhh h!h'h5h)}r¥(h-]h.]h,]h+]r¦Udeleting-messages-and-queuesr§ah/]r¨hauh2Kòh3hh4]r©(h=)rª}r«(hXDeleting Messages and Queuesr¬hj£h h!h'hAh)}r­(h-]h.]h,]h+]h/]uh2Kòh3hh4]r®hDXDeleting Messages and Queuesr¯…r°}r±(hj¬hjªubaubhH)r²}r³(hX{As stated above, messages are never deleted by the queue unless explicitly told to do so. To remove a message from a queue:r´hj£h h!h'hLh)}rµ(h-]h.]h,]h+]h/]uh2Kóh3hh4]r¶hDX{As stated above, messages are never deleted by the queue unless explicitly told to do so. To remove a message from a queue:r·…r¸}r¹(hj´hj²ubaubjT)rº}r»(hX>>> q.delete_message(m) []hj£h h!h'jWh)}r¼(hmhnh+]h,]h-]h.]h/]uh2K÷h3hh4]r½hDX>>> q.delete_message(m) []r¾…r¿}rÀ(hUhjºubaubhH)rÁ}rÂ(hX2If I want to delete the entire queue, I would use:rÃhj£h h!h'hLh)}rÄ(h-]h.]h,]h+]h/]uh2Kùh3hh4]rÅhDX2If I want to delete the entire queue, I would use:rÆ…rÇ}rÈ(hjÃhjÁubaubjT)rÉ}rÊ(hX>>> conn.delete_queue(q)rËhj£h h!h'jWh)}rÌ(hmhnh+]h,]h-]h.]h/]uh2Kûh3hh4]rÍhDX>>> conn.delete_queue(q)rÎ…rÏ}rÐ(hUhjÉubaubhH)rÑ}rÒ(hXNThis will delete the queue, even if there are still messages within the queue.rÓhj£h h!h'hLh)}rÔ(h-]h.]h,]h+]h/]uh2Kýh3hh4]rÕhDXNThis will delete the queue, even if there are still messages within the queue.rÖ…r×}rØ(hjÓhjÑubaubeubh)rÙ}rÚ(hUhhh h!h'h5h)}rÛ(h-]h.]h,]h+]rÜUadditional-informationrÝah/]rÞhauh2Mh3hh4]rß(h=)rà}rá(hXAdditional InformationrâhjÙh h!h'hAh)}rã(h-]h.]h,]h+]h/]uh2Mh3hh4]rähDXAdditional Informationrå…ræ}rç(hjâhjàubaubhH)rè}ré(hXThe above tutorial covers the basic operations of creating queues, writing messages, reading messages, deleting messages, and deleting queues. There are a few utility methods in boto that might be useful as well. For example, to count the number of messages in a queue:rêhjÙh h!h'hLh)}rë(h-]h.]h,]h+]h/]uh2Mh3hh4]rìhDXThe above tutorial covers the basic operations of creating queues, writing messages, reading messages, deleting messages, and deleting queues. There are a few utility methods in boto that might be useful as well. For example, to count the number of messages in a queue:rí…rî}rï(hjêhjèubaubjT)rð}rñ(hX>>> q.count() 10hjÙh h!h'jWh)}rò(hmhnh+]h,]h-]h.]h/]uh2Mh3hh4]róhDX>>> q.count() 10rô…rõ}rö(hUhjðubaubhH)r÷}rø(hXThis can be handy but this command as well as the other two utility methods I'll describe in a minute are inefficient and should be used with caution on queues with lots of messages (e.g. many hundreds or more). Similarly, you can clear (delete) all messages in a queue with:rùhjÙh h!h'hLh)}rú(h-]h.]h,]h+]h/]uh2M h3hh4]rûhDXThis can be handy but this command as well as the other two utility methods I'll describe in a minute are inefficient and should be used with caution on queues with lots of messages (e.g. many hundreds or more). Similarly, you can clear (delete) all messages in a queue with:rü…rý}rþ(hjùhj÷ubaubjT)rÿ}r(hX >>> q.clear()rhjÙh h!h'jWh)}r(hmhnh+]h,]h-]h.]h/]uh2Mh3hh4]rhDX >>> q.clear()r…r}r(hUhjÿubaubhH)r}r(hXlBe REAL careful with that one! Finally, if you want to dump all of the messages in a queue to a local file:r hjÙh h!h'hLh)}r (h-]h.]h,]h+]h/]uh2Mh3hh4]r hDXlBe REAL careful with that one! Finally, if you want to dump all of the messages in a queue to a local file:r …r }r(hj hjubaubjT)r}r(hX8>>> q.dump('messages.txt', sep='\n------------------\n')rhjÙh h!h'jWh)}r(hmhnh+]h,]h-]h.]h/]uh2Mh3hh4]rhDX8>>> q.dump('messages.txt', sep='\n------------------\n')r…r}r(hUhjubaubhH)r}r(hXàThis will read all of the messages in the queue and write the bodies of each of the messages to the file messages.txt. The optional ``sep`` argument is a separator that will be printed between each message body in the file.hjÙh h!h'hLh)}r(h-]h.]h,]h+]h/]uh2Mh3hh4]r(hDX…This will read all of the messages in the queue and write the bodies of each of the messages to the file messages.txt. The optional r…r}r(hX…This will read all of the messages in the queue and write the bodies of each of the messages to the file messages.txt. The optional hjubh)r}r(hX``sep``h)}r (h-]h.]h,]h+]h/]uhjh4]r!hDXsepr"…r#}r$(hUhjubah'h•ubhDXT argument is a separator that will be printed between each message body in the file.r%…r&}r'(hXT argument is a separator that will be printed between each message body in the file.hjubeubeubeubh h!h'h5h)}r((h-]h.]h,]h+]r)Ureading-message-attributesr*ah/]r+h auh2Kåh3hh4]r,(h=)r-}r.(hXReading Message Attributesr/hhh h!h'hAh)}r0(h-]h.]h,]h+]h/]uh2Kåh3hh4]r1hDXReading Message Attributesr2…r3}r4(hj/hj-ubaubhH)r5}r6(hX±By default, no arbitrary message attributes are returned when requesting messages. You can change this behavior by specifying the names of attributes you wish to have returned::hhh h!h'hLh)}r7(h-]h.]h,]h+]h/]uh2Kæh3hh4]r8hDX°By default, no arbitrary message attributes are returned when requesting messages. You can change this behavior by specifying the names of attributes you wish to have returned:r9…r:}r;(hX°By default, no arbitrary message attributes are returned when requesting messages. You can change this behavior by specifying the names of attributes you wish to have returned:hj5ubaubhh)r<}r=(hX~>>> rs = queue.get_messages(message_attributes=['name1', 'name2']) >>> print rs[0].message_attributes['name1']['string_value']hhh h!h'hkh)}r>(hmhnh+]h,]h-]h.]h/]uh2Kêh3hh4]r?hDX~>>> rs = queue.get_messages(message_attributes=['name1', 'name2']) >>> print rs[0].message_attributes['name1']['string_value']r@…rA}rB(hUhj<ubaubhH)rC}rD(hX'I am a string'rEhhh h!h'hLh)}rF(h-]h.]h,]h+]h/]uh2Kìh3hh4]rGhDX'I am a string'rH…rI}rJ(hjEhjCubaubhH)rK}rL(hX^A special value of ``All`` or ``.*`` may be passed to return all available message attributes.hhh h!h'hLh)}rM(h-]h.]h,]h+]h/]uh2Kîh3hh4]rN(hDXA special value of rO…rP}rQ(hXA special value of hjKubh)rR}rS(hX``All``h)}rT(h-]h.]h,]h+]h/]uhjKh4]rUhDXAllrV…rW}rX(hUhjRubah'h•ubhDX or rY…rZ}r[(hX or hjKubh)r\}r](hX``.*``h)}r^(h-]h.]h,]h+]h/]uhjKh4]r_hDX.*r`…ra}rb(hUhj\ubah'h•ubhDX: may be passed to return all available message attributes.rc…rd}re(hX: may be passed to return all available message attributes.hjKubeubeubh h!h'Usystem_messagerfh)}rg(h-]UlevelKh+]h,]Usourceh!h.]h/]UlineKìUtypeUERRORrhuh2Këh3hh4]rihH)rj}rk(hUh)}rl(h-]h.]h,]h+]h/]uhhh4]rmhDX#Inconsistent literal block quoting.rn…ro}rp(hUhjjubah'hLubaubaUcurrent_sourcerqNU decorationrrNUautofootnote_startrsKUnameidsrt}ru(hjOhj§hhÆh j h h1h j*h hÿh hVhjAhjÝhj…hh8uh4]rv(h%hehUU transformerrwNU footnote_refsrx}ryUrefnamesrz}r{Usymbol_footnotesr|]r}Uautofootnote_refsr~]rUsymbol_footnote_refsr€]rU citationsr‚]rƒh3hU current_liner„NUtransform_messagesr…]r†h)r‡}rˆ(hUh)}r‰(h-]UlevelKh+]h,]Usourceh!h.]h/]UlineKUtypeUINFOrŠuh4]r‹hH)rŒ}r(hUh)}rŽ(h-]h.]h,]h+]h/]uhj‡h4]rhDX-Hyperlink target "sqs-tut" is not referenced.r…r‘}r’(hUhjŒubah'hLubah'jfubaUreporterr“NUid_startr”KU autofootnotesr•]r–U citation_refsr—}r˜Uindirect_targetsr™]ršUsettingsr›(cdocutils.frontend Values rœor}rž(Ufootnote_backlinksrŸKUrecord_dependenciesr NU rfc_base_urlr¡Uhttp://tools.ietf.org/html/r¢U tracebackr£ˆUpep_referencesr¤NUstrip_commentsr¥NU toc_backlinksr¦Uentryr§U language_coder¨Uenr©U datestamprªNU report_levelr«KU _destinationr¬NU halt_levelr­KU strip_classesr®NhANUerror_encoding_error_handlerr¯Ubackslashreplacer°Udebugr±NUembed_stylesheetr²‰Uoutput_encoding_error_handlerr³Ustrictr´U sectnum_xformrµKUdump_transformsr¶NU docinfo_xformr·KUwarning_streamr¸NUpep_file_url_templater¹Upep-%04drºUexit_status_levelr»KUconfigr¼NUstrict_visitorr½NUcloak_email_addressesr¾ˆUtrim_footnote_reference_spacer¿‰UenvrÀNUdump_pseudo_xmlrÁNUexpose_internalsrÂNUsectsubtitle_xformrÉU source_linkrÄNUrfc_referencesrÅNUoutput_encodingrÆUutf-8rÇU source_urlrÈNUinput_encodingrÉU utf-8-sigrÊU_disable_configrËNU id_prefixrÌUU tab_widthrÍKUerror_encodingrÎUUTF-8rÏU_sourcerÐh!Ugettext_compactrшU generatorrÒNUdump_internalsrÓNU smart_quotesrÔ‰U pep_base_urlrÕUhttp://www.python.org/dev/peps/rÖUsyntax_highlightr×UlongrØUinput_encoding_error_handlerrÙj´Uauto_id_prefixrÚUidrÛUdoctitle_xformr܉Ustrip_elements_with_classesrÝNU _config_filesrÞ]Ufile_insertion_enabledr߈U raw_enabledràKU dump_settingsráNubUsymbol_footnote_startrâKUidsrã}rä(hÿhûj§j£jAj=jÝjÙjOjKj*hj…jhÆhÂh8hj jh1hhVhRuUsubstitution_namesrå}ræh'h3h)}rç(h-]h+]h,]Usourceh!h.]h/]uU footnotesrè]réUrefidsrê}rëh1]rìh%asub.