amqp 0.8.0.rc10 → 0.8.0.rc11

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,6 @@
1
1
  = Version 0.8.0
2
2
 
3
+ * [FEATURE] Returned messages, including header & content via AMQP::Exchange#on_publish. Callback accepts 3 args: basic_return, header, body
3
4
  * [BUG] Ruby 1.8.7-p249 is not supported because of this (p249-specific) Ruby bug: http://bit.ly/iONBmH
4
5
  * [FEATURE] AMQP::Utilities::EventLoopHelper detects app server (if any) being used and starts EventMachine reactor in an optimal way.
5
6
  * [FEATURE] AMQP 0.9.1 support, including tx.* operations class.
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  # Dependencies
24
24
  s.add_dependency "eventmachine"
25
- s.add_dependency "amq-client", ">= 0.7.0.alpha21"
25
+ s.add_dependency "amq-client", ">= 0.7.0.alpha23"
26
26
 
27
27
  begin
28
28
  require "changelog"
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "bundler"
5
+ Bundler.setup
6
+
7
+ $:.unshift(File.expand_path("../../../lib", __FILE__))
8
+
9
+ require 'amqp'
10
+
11
+
12
+ puts "=> Authentication failure/vhost misconfiguration handling with a rescue block"
13
+ puts
14
+
15
+ handler = Proc.new { |settings| puts "Failed to connect, as expected"; EM.stop }
16
+ connection_settings = {
17
+ :port => 5672,
18
+ :vhost => "/a/b/c/d/#{rand}/#{Time.now.to_i}",
19
+ :user => "amq_client_gem",
20
+ :password => "amq_client_gem_password_that_is_incorrect #{Time.now.to_i}",
21
+ :timeout => 0.3,
22
+ :on_tcp_connection_failure => handler
23
+ }
24
+
25
+
26
+ begin
27
+ AMQP.start(connection_settings) do |connection, open_ok|
28
+ raise "This should not be reachable"
29
+ end
30
+ rescue AMQP::PossibleAuthenticationFailureError => afe
31
+ puts "Authentication failed, as expected, caught #{afe.inspect}"
32
+ EventMachine.stop if EventMachine.reactor_running?
33
+ end
@@ -31,7 +31,7 @@ EventMachine.next_tick {
31
31
  }
32
32
  end
33
33
 
34
- exchange.publish "Hello, world!", :routing_key => queue.name
34
+ exchange.publish "Hello, world!", :routing_key => queue.name
35
35
  }
36
36
 
37
37
  t.join
@@ -0,0 +1,399 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "bundler"
5
+ Bundler.setup
6
+
7
+ $:.unshift(File.expand_path("../../lib", __FILE__))
8
+
9
+ require 'amqp'
10
+
11
+ t = Thread.new { EventMachine.run }
12
+ if defined?(JRUBY_VERSION)
13
+ # on the JVM, event loop startup takes longer and .next_tick behavior
14
+ # seem to be a bit different. Blocking current thread for a moment helps.
15
+ sleep 0.5
16
+ end
17
+
18
+ EventMachine.next_tick {
19
+ connection = AMQP.connect(:host => '127.0.0.1')
20
+ puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
21
+
22
+ channel = AMQP::Channel.new(connection)
23
+ queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => true)
24
+ exchange = channel.direct("")
25
+
26
+ queue.subscribe do |payload|
27
+ puts "Received a message #{payload.bytesize} bytes in size.\n\nDisconnecting..."
28
+
29
+ connection.close {
30
+ EM.stop { exit }
31
+ }
32
+ end
33
+
34
+
35
+ message = <<-MESSAGE
36
+ Historical origin
37
+
38
+ In May, 1974, the Institute of Electrical and Electronic Engineers (IEEE) published a paper entitled "A Protocol for Packet Network Interconnection."[1] The paper's authors, Vinton G. Cerf and Bob Kahn, described an internetworking protocol for sharing resources using packet-switching among the nodes. A central control component of this model was the Transmission Control Program that incorporated both connection-oriented links and datagram services between hosts. The monolithic Transmission Control Program was later divided into a modular architecture consisting of the Transmission Control Protocol at the connection-oriented layer and the Internet Protocol at the internetworking (datagram) layer. The model became known informally as TCP/IP, although formally it was henceforth called the Internet Protocol Suite.
39
+ Network function
40
+
41
+ TCP provides a communication service at an intermediate level between an application program and the Internet Protocol (IP). That is, when an application program desires to send a large chunk of data across the Internet using IP, instead of breaking the data into IP-sized pieces and issuing a series of IP requests, the software can issue a single request to TCP and let TCP handle the IP details.
42
+
43
+ IP works by exchanging pieces of information called packets. A packet is a sequence of octets and consists of a header followed by a body. The header describes the packet's destination and, optionally, the routers to use for forwarding until it arrives at its destination. The body contains the data IP is transmitting.
44
+
45
+ Due to network congestion, traffic load balancing, or other unpredictable network behavior, IP packets can be lost, duplicated, or delivered out of order. TCP detects these problems, requests retransmission of lost data, rearranges out-of-order data, and even helps minimize network congestion to reduce the occurrence of the other problems. Once the TCP receiver has reassembled the sequence of octets originally transmitted, it passes them to the application program. Thus, TCP abstracts the application's communication from the underlying networking details.
46
+
47
+ TCP is utilized extensively by many of the Internet's most popular applications, including the World Wide Web (WWW), E-mail, File Transfer Protocol, Secure Shell, peer-to-peer file sharing, and some streaming media applications.
48
+
49
+ TCP is optimized for accurate delivery rather than timely delivery, and therefore, TCP sometimes incurs relatively long delays (in the order of seconds) while waiting for out-of-order messages or retransmissions of lost messages. It is not particularly suitable for real-time applications such as Voice over IP. For such applications, protocols like the Real-time Transport Protocol (RTP) running over the User Datagram Protocol (UDP) are usually recommended instead.[2]
50
+
51
+ TCP is a reliable stream delivery service that guarantees delivery of a data stream sent from one host to another without duplication or losing data. Since packet transfer is not reliable, a technique known as positive acknowledgment with retransmission is used to guarantee reliability of packet transfers. This fundamental technique requires the receiver to respond with an acknowledgment message as it receives the data. The sender keeps a record of each packet it sends, and waits for acknowledgment before sending the next packet. The sender also keeps a timer from when the packet was sent, and retransmits a packet if the timer expires. The timer is needed in case a packet gets lost or corrupted.[2]
52
+
53
+ TCP consists of a set of rules: for the protocol, that are used with the Internet Protocol, and for the IP, to send data "in a form of message units" between computers over the Internet. At the same time that IP takes care of handling the actual delivery of the data, TCP takes care of keeping track of the individual units of data transmission, called segments, that a message is divided into for efficient routing through the network. For example, when an HTML file is sent from a Web server, the TCP software layer of that server divides the sequence of octets of the file into segments and forwards them individually to the IP software layer (Internet Layer). The Internet Layer encapsulates each TCP segment into an IP packet by adding a header that includes (among other data) the destination IP address. Even though every packet has the same destination address, they can be routed on different paths through the network. When the client program on the destination computer receives them, the TCP layer (Transport Layer) reassembles the individual segments and ensures they are correctly ordered and error free as it streams them to an application.
54
+ TCP segment structure
55
+
56
+ Transmission Control Protocol accepts data from a data stream, 'segments' it into chunks, and adds a TCP header creating a TCP segment. The TCP segment is then encapsulated into an IP datagram. A TCP segment is "the packet of information that TCP uses to exchange data with its peers." [3]
57
+
58
+ Note that the term TCP packet, though sometimes informally used, is not in line with current terminology, where segment refers to the TCP PDU (Protocol Data Unit), datagram[4] to the IP PDU and frame to the data link layer PDU:
59
+
60
+ Processes transmit data by calling on the TCP and passing buffers of data as arguments. The TCP packages the data from these buffers into segments and calls on the internet module [e.g. IP] to transmit each segment to the destination TCP.[5]
61
+
62
+ A TCP segment consists of a segment header and a data section. The TCP header contains 10 mandatory fields, and an optional extension field (Options, pink background in table).
63
+
64
+ The data section follows the header. Its contents are the payload data carried for the application. The length of the data section is not specified in the TCP segment header. It can be calculated by subtracting the combined length of the TCP header and the encapsulating IP segment header from the total IP segment length (specified in the IP segment header).
65
+ TCP Header Bit offset 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
66
+ 0 Source port Destination port
67
+ 32 Sequence number
68
+ 64 Acknowledgment number (if ACK set)
69
+ 96 Data offset Reserved C
70
+ W
71
+ R E
72
+ C
73
+ E U
74
+ R
75
+ G A
76
+ C
77
+ K P
78
+ S
79
+ H R
80
+ S
81
+ T S
82
+ Y
83
+ N F
84
+ I
85
+ N Window Size
86
+ 128 Checksum Urgent pointer (if URG set)
87
+ 160
88
+ ... Options (if Data Offset > 5)
89
+ ... padding
90
+
91
+ Source port (16 bits) – identifies the sending port
92
+ Destination port (16 bits) – identifies the receiving port
93
+ Sequence number (32 bits) – has a dual role:
94
+
95
+ If the SYN flag is set (1), then this is the initial sequence number. The sequence number of the actual first data byte and the acknowledged number in the corresponding ACK are then this sequence number plus 1.
96
+ If the SYN flag is clear (0), then this is the accumulated sequence number of the first data byte of this packet for the current session.
97
+
98
+ Acknowledgment number (32 bits) – if the ACK flag is set then the value of this field is the next sequence number that the receiver is expecting. This acknowledges receipt of all prior bytes (if any). The first ACK sent by each end acknowledges the other end's initial sequence number itself, but no data.
99
+ Data offset (4 bits) – specifies the size of the TCP header in 32-bit words. The minimum size header is 5 words and the maximum is 15 words thus giving the minimum size of 20 bytes and maximum of 60 bytes, allowing for up to 40 bytes of options in the header. This field gets its name from the fact that it is also the offset from the start of the TCP segment to the actual data.
100
+ Reserved (4 bits) – for future use and should be set to zero
101
+ Flags (8 bits) (aka Control bits) – contains 8 1-bit flags
102
+
103
+ CWR (1 bit) – Congestion Window Reduced (CWR) flag is set by the sending host to indicate that it received a TCP segment with the ECE flag set and had responded in congestion control mechanism (added to header by RFC 3168).
104
+ ECE (1 bit) – ECN-Echo indicates
105
+
106
+ If the SYN flag is set (1), that the TCP peer is ECN capable.
107
+ If the SYN flag is clear (0), that a packet with Congestion Experienced flag in IP header set is received during normal transmission (added to header by RFC 3168).
108
+
109
+ URG (1 bit) – indicates that the Urgent pointer field is significant
110
+ ACK (1 bit) – indicates that the Acknowledgment field is significant. All packets after the initial SYN packet sent by the client should have this flag set.
111
+ PSH (1 bit) – Push function. Asks to push the buffered data to the receiving application.
112
+ RST (1 bit) – Reset the connection
113
+ SYN (1 bit) – Synchronize sequence numbers. Only the first packet sent from each end should have this flag set. Some other flags change meaning based on this flag, and some are only valid for when it is set, and others when it is clear.
114
+ FIN (1 bit) – No more data from sender
115
+
116
+ Window size (16 bits) – the size of the receive window, which specifies the number of bytes (beyond the sequence number in the acknowledgment field) that the receiver is currently willing to receive (see Flow control and Window Scaling)
117
+ Checksum (16 bits) – The 16-bit checksum field is used for error-checking of the header and data
118
+ Urgent pointer (16 bits) – if the URG flag is set, then this 16-bit field is an offset from the sequence number indicating the last urgent data byte
119
+ Options (Variable 0-320 bits, divisible by 32) – The length of this field is determined by the data offset field. Options 0 and 1 are a single byte (8 bits) in length. The remaining options indicate the total length of the option (expressed in bytes) in the second byte.
120
+ Padding – The TCP header padding is used to ensure that the TCP header ends and data begins on a 32 bit boundary. The padding is composed of zeros.[6]
121
+
122
+ Some options may only be sent when SYN is set; they are indicated below as [SYN].
123
+
124
+ 0 (8 bits) - End of options list
125
+ 1 (8 bits) - No operation (NOP, Padding) This may be used to align option fields on 32-bit boundaries for better performance.
126
+ 2,4,SS (32 bits) - Maximum segment size (see maximum segment size) [SYN]
127
+ 3,3,S (24 bits) - Window scale (see window scaling for details) [SYN][7]
128
+ 4,2 (16 bits) - Selective Acknowledgement permitted. [SYN] (See selective acknowledgments for details)[8]
129
+ 5,N,BBBB,EEEE,... (variable bits, N is either 10, 18, 26, or 34)- Selective ACKnowledgement (SACK)[9] These first two bytes are followed by a list of 1-4 blocks being selectively acknowledged, specified as 32-bit begin/end pointers.
130
+ 8,10,TTTT,EEEE (80 bits)- Timestamp and echo of previous timestamp (see TCP timestamps for details)[10]
131
+ 14,3,S (24 bits) - TCP Alternate Checksum Request. [SYN][11]
132
+ 15,N,... (variable bits) - TCP Alternate Checksum Data.
133
+
134
+ (The remaining options are obsolete, experimental, not yet standardized, or unassigned)
135
+
136
+ Protocol operation
137
+ A Simplified TCP State Diagram. See TCP EFSM diagram for a more detailed state diagram including the states inside the ESTABLISHED state.
138
+
139
+ TCP protocol operations may be divided into three phases. Connections must be properly established in a multi-step handshake process (connection establishment) before entering the data transfer phase. After data transmission is completed, the connection termination closes established virtual circuits and releases all allocated resources.
140
+
141
+ A TCP connection is managed by an operating system through a programming interface that represents the local end-point for communications, the Internet socket. During the lifetime of a TCP connection it undergoes a series of state changes:[12]
142
+
143
+ LISTENING : In case of a server, waiting for a connection request from any remote client.
144
+ SYN-SEND : waiting for the remote peer to send back a TCP segment with the SYN and ACK flags set. (usually set by TCP clients)
145
+ SYN-RECEIVED : waiting for the remote peer to send back an acknowledgment after having sent back a connection acknowledgment to the remote peer. (usually set by TCP servers)
146
+ ESTABLISHED : the port is ready to receive/send data from/to the remote peer.
147
+ FIN-WAIT-1 :
148
+ FIN-WAIT-2 :Indicates that the client is waiting for the servers fin segment ( which indicates the servers application process is ready to close and the server is ready to initiate it's side of the connection termination)
149
+ CLOSE-WAIT :
150
+ LAST-ACK : indicates that the server is in the process of sending it's own fin segment ( which indicates the server's application process is ready to close and the server is ready to initiate it's side of the connection termination )
151
+ TIME-WAIT : represents waiting for enough time to pass to be sure the remote peer received the acknowledgment of its connection termination request. According to RFC 793 a connection can stay in TIME-WAIT for a maximum of four minutes know as a MSL (maximum segment lifetime).
152
+ CLOSED : connection is closed
153
+
154
+ Connection establishment
155
+
156
+ To establish a connection, TCP uses a three-way handshake. Before a client attempts to connect with a server, the server must first bind to a port to open it up for connections: this is called a passive open. Once the passive open is established, a client may initiate an active open. To establish a connection, the three-way (or 3-step) handshake occurs:
157
+
158
+ SYN: The active open is performed by the client sending a SYN to the server. It sets the segment's sequence number to a random value A.
159
+ SYN-ACK: In response, the server replies with a SYN-ACK. The acknowledgment number is set to one more than the received sequence number (A + 1), and the sequence number that the server chooses for the packet is another random number, B.
160
+ ACK: Finally, the client sends an ACK back to the server. The sequence number is set to the received acknowledgement value i.e. A + 1, and the acknowledgement number is set to one more than the received sequence number i.e. B + 1.
161
+
162
+ At this point, both the client and server have received an acknowledgment of the connection.
163
+ Resource usage
164
+
165
+ Most implementations allocate an entry in a table that maps a session to a running operating system process. Because TCP packets do not include a session identifier, both endpoints identify the session using the client's address and port. Whenever a packet is received, the TCP implementation must perform a lookup on this table to find the destination process.
166
+
167
+ The number of sessions in the server side is limited only by memory and can grow as new connections arrive, but the client must allocate a random port before sending the first SYN to the server. This port remains allocated during the whole conversation, and effectively limits the number of outgoing connections from each of the client's IP addresses. If an application fails to properly close unrequired connections, a client can run out of resources and become unable to establish new TCP connections, even from other applications.
168
+
169
+ Both endpoints must also allocate space for unacknowledged packets and received (but unread) data.
170
+ Data transfer
171
+
172
+ There are a few key features that set TCP apart from User Datagram Protocol:
173
+
174
+ Ordered data transfer - the destination host rearranges according to sequence number[2]
175
+ Retransmission of lost packets - any cumulative stream not acknowledged is retransmitted[2]
176
+ Error-free data transfer[13]
177
+ Flow control - limits the rate a sender transfers data to guarantee reliable delivery. The receiver continually hints the sender on how much data can be received (controlled by the sliding window). When the receiving host's buffer fills, the next acknowledgment contains a 0 in the window size, to stop transfer and allow the data in the buffer to be processed.[2]
178
+ Congestion control [2]
179
+
180
+ Reliable transmission
181
+
182
+ TCP uses a sequence number to identify each segment of data. The sequence number identifies the order of the segments sent from each computer so that the data can be reconstructed in order, regardless of any fragmentation, disordering, or packet loss that may occur during transmission. For every payload segment transmitted the sequence number must be incremented. In the first two steps of the 3-way handshake, both computers exchange an initial sequence number (ISN). This number can be arbitrary, and should in fact be unpredictable to defend against TCP Sequence Prediction Attacks.
183
+
184
+ TCP primarily uses a cumulative acknowledgment scheme, where the receiver sends an acknowledgment signifying that the receiver has received all data preceding the acknowledged sequence number. Essentially, the first byte in a segment's data field is assigned a sequence number, which is inserted in the sequence number field, and the receiver sends an acknowledgment specifying the sequence number of the next segment they expect to receive. For example, if computer A sends 4 segments with a sequence number of 100 (conceptually, the four segments would have a sequence number of 100, 101, 102 and 103 assigned) then the receiver would send back an acknowledgment of 104 since that is the next segment it expects to receive in the next packet.
185
+
186
+ In addition to cumulative acknowledgments, TCP receivers can also send selective acknowledgments to provide further information.
187
+
188
+ If the sender infers that data has been lost in the network, it retransmits the data.
189
+ Error detection
190
+
191
+ Sequence numbers and acknowledgments cover discarding duplicate packets, retransmission of lost packets, and ordered-data transfer. To assure correctness a checksum field is included (see TCP segment structure for details on checksumming).
192
+
193
+ The TCP checksum is a weak check by modern standards. Data Link Layers with high bit error rates may require additional link error correction/detection capabilities. The weak checksum is partially compensated for by the common use of a CRC or better integrity check at layer 2, below both TCP and IP, such as is used in PPP or the Ethernet frame. However, this does not mean that the 16-bit TCP checksum is redundant: remarkably, introduction of errors in packets between CRC-protected hops is common, but the end-to-end 16-bit TCP checksum catches most of these simple errors.[14] This is the end-to-end principle at work.
194
+ Flow control
195
+
196
+ TCP uses an end-to-end flow control protocol to avoid having the sender send data too fast for the TCP receiver to receive and process it reliably. Having a mechanism for flow control is essential in an environment where machines of diverse network speeds communicate. For example, if a PC sends data to a hand-held PDA that is slowly processing received data, the PDA must regulate data flow so as not to be overwhelmed.[2]
197
+
198
+ TCP uses a sliding window flow control protocol. In each TCP segment, the receiver specifies in the receive window field the amount of additional received data (in bytes) that it is willing to buffer for the connection. The sending host can send only up to that amount of data before it must wait for an acknowledgment and window update from the receiving host.
199
+ TCP sequence numbers and receive windows behave very much like a clock. The receive window shifts each time the receiver receives and acknowledges a new segment of data. Once it runs out of sequence numbers, the sequence number loops back to 0.
200
+
201
+ When a receiver advertises a window size of 0, the sender stops sending data and starts the persist timer. The persist timer is used to protect TCP from a deadlock situation that could arise if a subsequent window size update from the receiver is lost, and the sender cannot send more data until receiving a new window size update from the receiver. When the persist timer expires, the TCP sender attempts recovery by sending a small packet so that the receiver responds by sending another acknowledgement containing the new window size.
202
+
203
+ If a receiver is processing incoming data in small increments, it may repeatedly advertise a small receive window. This is referred to as the silly window syndrome, since it is inefficient to send only a few bytes of data in a TCP segment, given the relatively large overhead of the TCP header. TCP senders and receivers typically employ flow control logic to specifically avoid repeatedly sending small segments. The sender-side silly window syndrome avoidance logic is referred to as Nagle's algorithm.
204
+ Congestion control
205
+
206
+ The final main aspect of TCP is congestion control. TCP uses a number of mechanisms to achieve high performance and avoid congestion collapse, where network performance can fall by several orders of magnitude. These mechanisms control the rate of data entering the network, keeping the data flow below a rate that would trigger collapse. They also yield an approximately max-min fair allocation between flows.
207
+
208
+ Acknowledgments for data sent, or lack of acknowledgments, are used by senders to infer network conditions between the TCP sender and receiver. Coupled with timers, TCP senders and receivers can alter the behavior of the flow of data. This is more generally referred to as congestion control and/or network congestion avoidance.
209
+
210
+ Modern implementations of TCP contain four intertwined algorithms: Slow-start, congestion avoidance, fast retransmit, and fast recovery (RFC 5681).
211
+
212
+ In addition, senders employ a retransmission timeout (RTO) that is based on the estimated round-trip time (or RTT) between the sender and receiver, as well as the variance in this round trip time. The behavior of this timer is specified in RFC 2988. There are subtleties in the estimation of RTT. For example, senders must be careful when calculating RTT samples for retransmitted packets; typically they use Karn's Algorithm or TCP timestamps (see RFC 1323). These individual RTT samples are then averaged over time to create a Smoothed Round Trip Time (SRTT) using Jacobson's algorithm. This SRTT value is what is finally used as the round-trip time estimate.
213
+
214
+ Enhancing TCP to reliably handle loss, minimize errors, manage congestion and go fast in very high-speed environments are ongoing areas of research and standards development. As a result, there are a number of TCP congestion avoidance algorithm variations.
215
+ Maximum segment size
216
+
217
+ The Maximum segment size (MSS) is the largest amount of data, specified in bytes, that TCP is willing to send in a single segment. For best performance, the MSS should be set small enough to avoid IP fragmentation, which can lead to excessive retransmissions if there is packet loss. To try to accomplish this, typically the MSS is negotiated using the MSS option when the TCP connection is established, in which case it is determined by the maximum transmission unit (MTU) size of the data link layer of the networks to which the sender and receiver are directly attached. Furthermore, TCP senders can use Path MTU discovery to infer the minimum MTU along the network path between the sender and receiver, and use this to dynamically adjust the MSS to avoid IP fragmentation within the network.
218
+
219
+ Strictly speaking, the MSS is not negotiated between the originator and the receiver, because that would imply that both originator and receiver will negotiate and agree upon a single, unified MSS that applies to all communication in both directions of the connection. In fact, two completely independent values of MSS are permitted for the two directions of data flow in a TCP connection.[15] This situation may arise, for example, if one of the devices participating in a connection has an extremely limited amount memory reserved (perhaps even smaller than the overall discovered Path MTU) for processing incoming TCP segments.
220
+ Selective acknowledgments
221
+
222
+ Relying purely on the cumulative acknowledgment scheme employed by the original TCP protocol can lead to inefficiencies when packets are lost. For example, suppose 10,000 bytes are sent in 10 different TCP packets, and the first packet is lost during transmission. In a pure cumulative acknowledgment protocol, the receiver cannot say that it received bytes 1,000 to 9,999 successfully, but failed to receive the first packet, containing bytes 0 to 999. Thus the sender may then have to resend all 10,000 bytes.
223
+
224
+ To solve this problem TCP employs the selective acknowledgment (SACK) option, defined in RFC 2018, which allows the receiver to acknowledge discontinuous blocks of packets that were received correctly, in addition to the sequence number of the last contiguous byte received successively, as in the basic TCP acknowledgment. The acknowledgement can specify a number of SACK blocks, where each SACK block is conveyed by the starting and ending sequence numbers of a contiguous range that the receiver correctly received. In the example above, the receiver would send SACK with sequence numbers 1,000 and 9,999. The sender thus retransmits only the first packet, bytes 0 to 999.
225
+
226
+ An extension to the SACK option is the "duplicate-SACK" option, defined in RFC 2883. An out-of-order packet delivery can often falsely indicate the TCP sender of lost packet and, in turn, the TCP sender retransmits the suspected-to-be-lost packet and slow down the data delivery to prevent network congestion. The TCP sender undoes the action of slow-down, that is a recovery of the original pace of data transmission, upon receiving a D-SACK that indicates the retransmitted packet is duplicate.
227
+
228
+ The SACK option is not mandatory and it is used only if both parties support it. This is negotiated when connection is established. SACK uses the optional part of the TCP header (see TCP segment structure for details). The use of SACK is widespread - all popular TCP stacks support it. Selective acknowledgment is also used in Stream Control Transmission Protocol (SCTP).
229
+ Window scaling
230
+ Main article: TCP window scale option
231
+
232
+ For more efficient use of high bandwidth networks, a larger TCP window size may be used. The TCP window size field controls the flow of data and its value is limited to between 2 and 65,535 bytes.
233
+
234
+ Since the size field cannot be expanded, a scaling factor is used. The TCP window scale option, as defined in RFC 1323, is an option used to increase the maximum window size from 65,535 bytes to 1 Gigabyte. Scaling up to larger window sizes is a part of what is necessary for TCP Tuning.
235
+
236
+ The window scale option is used only during the TCP 3-way handshake. The window scale value represents the number of bits to left-shift the 16-bit window size field. The window scale value can be set from 0 (no shift) to 14 for each direction independently. Both sides must send the option in their SYN segments to enable window scaling in either direction.
237
+
238
+ Some routers and packet firewalls rewrite the window scaling factor during a transmission. This causes sending and receiving sides to assume different TCP window sizes. The result is non-stable traffic that may be very slow. The problem is visible on some sending and receiving sites behind the path of defective routers.[16]
239
+ TCP timestamps
240
+
241
+ TCP timestamps, defined in RFC 1323, help TCP compute the round-trip time between the sender and receiver. Timestamp options include a 4-byte timestamp value, where the sender inserts its current value of its timestamp clock, and a 4-byte echo reply timestamp value, where the receiver generally inserts the most recent timestamp value that it has received. The sender uses the echo reply timestamp in an acknowledgement to compute the total elapsed time since the acknowledged segment was sent.[2]
242
+
243
+ TCP timestamps are also used to help in the case where TCP sequence numbers encounter their 232 bound and "wrap around" the sequence number space. This scheme is known as Protect Against Wrapped Sequence numbers, or PAWS (see RFC 1323 for details). Furthermore, the Eifel detection algorithm, defined in RFC 3522, which detects unnecessary loss recovery requires TCP timestamps.
244
+ Out of band data
245
+
246
+ One is able to interrupt or abort the queued stream instead of waiting for the stream to finish. This is done by specifying the data as urgent. This tells the receiving program to process it immediately, along with the rest of the urgent data. When finished, TCP informs the application and resumes back to the stream queue. An example is when TCP is used for a remote login session, the user can send a keyboard sequence that interrupts or aborts the program at the other end. These signals are most often needed when a program on the remote machine fails to operate correctly. The signals must be sent without waiting for the program to finish its current transfer.[2]
247
+
248
+ TCP OOB data was not designed for the modern Internet. The urgent pointer only alters the processing on the remote host and doesn't expedite any processing on the network itself. When it gets to the remote host there are two slightly different interpretations of the protocol, which means only single bytes of OOB data are reliable. This is assuming it's reliable at all as it's one of the least commonly used protocol elements and tends to be poorly implemented. [17][18]
249
+ Forcing data delivery
250
+
251
+ Normally, TCP waits for the buffer to exceed the maximum segment size before sending any data. This creates serious delays when the two sides of the connection are exchanging short messages and need to receive the response before continuing. For example, the login sequence at the beginning of a telnet session begins with the short message "Login", and the session cannot make any progress until these five characters have been transmitted and the response has been received. This process can be seriously delayed by TCP's normal behavior when the message is provided to TCP in several send calls.
252
+
253
+ However, an application can force delivery of segments to the output stream using a push operation provided by TCP to the application layer.[2] This operation also causes TCP to set the PSH flag or control bit to ensure that data is delivered immediately to the application layer by the receiving transport layer.
254
+
255
+ In the most extreme cases, for example when a user expects each keystroke to be echoed by the receiving application, the push operation can be used each time a keystroke occurs. More generally, application programs use this function to force output to be sent after writing a character or line of characters. By forcing the data to be sent immediately, delays and wait time are reduced.
256
+ Connection termination
257
+
258
+ The connection termination phase uses, at most, a four-way handshake, with each side of the connection terminating independently. When an endpoint wishes to stop its half of the connection, it transmits a FIN packet, which the other end acknowledges with an ACK. Therefore, a typical tear-down requires a pair of FIN and ACK segments from each TCP endpoint. After both FIN/ACK exchanges are concluded, the terminating side waits for a timeout before finally closing the connection, during which time the local port is unavailable for new connections; this prevents confusion due to delayed packets being delivered during subsequent connections.
259
+
260
+ A connection can be "half-open", in which case one side has terminated its end, but the other has not. The side that has terminated can no longer send any data into the connection, but the other side can. The terminating side should continue reading the data until the other side terminates as well.
261
+
262
+ It is also possible to terminate the connection by a 3-way handshake, when host A sends a FIN and host B replies with a FIN & ACK (merely combines 2 steps into one) and host A replies with an ACK.[19] This is perhaps the most common method.
263
+
264
+ It is possible for both hosts to send FINs simultaneously then both just have to ACK. This could possibly be considered a 2-way handshake since the FIN/ACK sequence is done in parallel for both directions.
265
+
266
+ Some host TCP stacks may implement a "half-duplex" close sequence, as Linux or HP-UX do. If such a host actively closes a connection but still has not read all the incoming data the stack already received from the link, this host sends a RST instead of a FIN (Section 4.2.2.13 in RFC 1122). This allows a TCP application to be sure the remote application has read all the data the former sent—waiting the FIN from the remote side, when it actively closes the connection. However, the remote TCP stack cannot distinguish between a Connection Aborting RST and this Data Loss RST. Both cause the remote stack to throw away all the data it received, but that the application still didn't read.[clarification needed]
267
+
268
+ Some application protocols may violate the OSI model layers, using the TCP open/close handshaking for the application protocol open/close handshaking - these may find the RST problem on active close. As an example:
269
+
270
+ s = connect(remote);
271
+ send(s, data);
272
+ close(s);
273
+
274
+ For a usual program flow like above, a TCP/IP stack like that described above does not guarantee that all the data arrives to the other application.
275
+ Vulnerabilities
276
+
277
+ TCP may be attacked in a variety of ways. The results of a thorough security assessment of the TCP, along with possible mitigations for the identified issues, was published in 2009,[20] and is currently being pursued within the IETF.[21]
278
+ Denial of service
279
+
280
+ By using a spoofed IP address and repeatedly sending purposely assembled SYN packets, attackers can cause the server to consume large amounts of resources keeping track of the bogus connections. This is known as a SYN flood attack. Proposed solutions to this problem include SYN cookies and Cryptographic puzzles. Sockstress is a similar attack, that might be mitigated with system resource management.[22] An advanced DoS attack involving the exploitation of the TCP Persist Timer was analyzed at Phrack #66.[23]
281
+ Connection hijacking
282
+ Main article: TCP sequence prediction attack
283
+
284
+ An attacker who is able to eavesdrop a TCP session and redirect packets can hijack a TCP connection. To do so, the attacker learns the sequence number from the ongoing communication and forges a false segment that looks like the next segment in the stream. Such a simple hijack can result in one packet being erroneously accepted at one end. When the receiving host acknowledges the extra segment to the other side of the connection, synchronization is lost. Hijacking might be combined with ARP or routing attacks that allow taking control of the packet flow, so as to get permanent control of the hijacked TCP connection.[24]
285
+
286
+ Impersonating a different IP address was not difficult prior to RFC 1948, when the initial sequence number was easily guessable. That allowed an attacker to blindly send a sequence of packets that the receiver would believe to come from a different IP address, without the need to deploy ARP or routing attacks: it is enough to ensure that the legitimate host of the impersonated IP address is down, or bring it to that condition using denial of service attacks. This is why the initial sequence number is chosen at random.
287
+ TCP ports
288
+ Main article: TCP and UDP port
289
+
290
+ TCP uses the notion of port numbers to identify sending and receiving application end-points on a host, or Internet sockets. Each side of a TCP connection has an associated 16-bit unsigned port number (0-65535) reserved by the sending or receiving application. Arriving TCP data packets are identified as belonging to a specific TCP connection by its sockets, that is, the combination of source host address, source port, destination host address, and destination port. This means that a server computer can provide several clients with several services simultaneously, as long as a client takes care of initiating any simultaneous connections to one destination port from different source ports.
291
+
292
+ Port numbers are categorized into three basic categories: well-known, registered, and dynamic/private. The well-known ports are assigned by the Internet Assigned Numbers Authority (IANA) and are typically used by system-level or root processes. Well-known applications running as servers and passively listening for connections typically use these ports. Some examples include: FTP (21), SSH (22), TELNET (23), SMTP (25) and HTTP (80). Registered ports are typically used by end user applications as ephemeral source ports when contacting servers, but they can also identify named services that have been registered by a third party. Dynamic/private ports can also be used by end user applications, but are less commonly so. Dynamic/private ports do not contain any meaning outside of any particular TCP connection.
293
+ Development
294
+
295
+ TCP is a complex protocol. However, while significant enhancements have been made and proposed over the years, its most basic operation has not changed significantly since its first specification RFC 675 in 1974, and the v4 specification RFC 793, published in September 1981. RFC 1122, Host Requirements for Internet Hosts, clarified a number of TCP protocol implementation requirements. RFC 2581, TCP Congestion Control, one of the most important TCP-related RFCs in recent years, describes updated algorithms that avoid undue congestion. In 2001, RFC 3168 was written to describe explicit congestion notification (ECN), a congestion avoidance signaling mechanism.
296
+
297
+ The original TCP congestion avoidance algorithm was known as "TCP Tahoe", but many alternative algorithms have since been proposed (including TCP Reno, TCP Vegas, FAST TCP, TCP New Reno, and TCP Hybla).
298
+
299
+ TCP Interactive (iTCP) [25] is a research effort into TCP extensions that allows applications to subscribe to TCP events and register handler components that can launch applications for various purposes, including application-assisted congestion control.
300
+
301
+ Multipath TCP (MPTCP) [26] is an ongoing effort within the IETF that aims at allowing a TCP connection to use multiple paths to maximise resource usage and increase redundancy. The redundancy offered by Multipath TCP in the context of wireless networks [27] enables statistical multiplexing of resources, and thus increases TCP throughput dramatically.
302
+
303
+ TCP Cookie Transactions (TCPCT) is an extension proposed in December 2009 to secure servers against denial-of-service attacks. Unlike SYN cookies, TCPCT does not conflict with other TCP extensions such as window scaling. TCPCT was designed due to necessities of DNSSEC, where servers have to handle large numbers of short-lived TCP connections.
304
+
305
+ tcpcrypt is an extension proposed in July 2010 to provide transport-level encryption directly in TCP itself. It's designed to work transparently and not require any configuration. Unlike TLS (SSL), tcpcrypt itself does not provide authentication, but provides simple primitives down to the application to do that. As of 2010, the first tcpcrypt IETF draft has been published and implementations exist for several major platforms.
306
+ TCP over wireless networks
307
+
308
+ TCP has been optimized for wired networks. Any packet loss is considered to be the result of network congestion and the congestion window size is reduced dramatically as a precaution. However, wireless links are known to experience sporadic and usually temporary losses due to fading, shadowing, hand off, and other radio effects, that cannot be considered congestion. After the (erroneous) back-off of the congestion window size, due to wireless packet loss, there can be a congestion avoidance phase with a conservative decrease in window size. This causes the radio link to be underutilized. Extensive research has been done on the subject of how to combat these harmful effects. Suggested solutions can be categorized as end-to-end solutions (which require modifications at the client or server),[28] link layer solutions (such as RLP in CDMA2000), or proxy based solutions (which require some changes in the network without modifying end nodes.[28][29]
309
+ Hardware implementations
310
+
311
+ One way to overcome the processing power requirements of TCP is to build hardware implementations of it, widely known as TCP Offload Engines (TOE). The main problem of TOEs is that they are hard to integrate into computing systems, requiring extensive changes in the operating system of the computer or device. One company to develop such a device was Alacritech.
312
+ Debugging
313
+
314
+ A packet sniffer, which intercepts TCP traffic on a network link, can be useful in debugging networks, network stacks and applications that use TCP by showing the user what packets are passing through a link. Some networking stacks support the SO_DEBUG socket option, which can be enabled on the socket using setsockopt. That option dumps all the packets, TCP states, and events on that socket, which is helpful in debugging. Netstat is another utility that can be used for debugging.
315
+ Alternatives
316
+
317
+ For many applications TCP is not appropriate. One big problem (at least with normal implementations) is that the application cannot get at the packets coming after a lost packet until the retransmitted copy of the lost packet is received. This causes problems for real-time applications such as streaming multimedia (such as Internet radio), real-time multiplayer games and voice over IP (VoIP) where it is sometimes more useful to get most of the data in a timely fashion than it is to get all of the data in order.
318
+
319
+ For both historical and performance reasons, most storage area networks (SANs) prefer to use Fibre Channel protocol (FCP) instead of TCP/IP.
320
+
321
+ Also for embedded systems, network booting and servers that serve simple requests from huge numbers of clients (e.g. DNS servers) the complexity of TCP can be a problem. Finally, some tricks such as transmitting data between two hosts that are both behind NAT (using STUN or similar systems) are far simpler without a relatively complex protocol like TCP in the way.
322
+
323
+ Generally, where TCP is unsuitable, the User Datagram Protocol (UDP) is used. This provides the application multiplexing and checksums that TCP does, but does not handle building streams or retransmission, giving the application developer the ability to code them in a way suitable for the situation, or to replace them with other methods like forward error correction or interpolation.
324
+
325
+ SCTP is another IP protocol that provides reliable stream oriented services similar to TCP. It is newer and considerably more complex than TCP, and has not yet seen widespread deployment. However, it is especially designed to be used in situations where reliability and near-real-time considerations are important.
326
+
327
+ Venturi Transport Protocol (VTP) is a patented proprietary protocol that is designed to replace TCP transparently to overcome perceived inefficiencies related to wireless data transport.
328
+
329
+ TCP also has issues in high bandwidth environments. The TCP congestion avoidance algorithm works very well for ad-hoc environments where the data sender is not known in advance, but if the environment is predictable, a timing based protocol such as Asynchronous Transfer Mode (ATM) can avoid TCP's retransmits overhead.
330
+
331
+ Multipurpose Transaction Protocol (MTP/IP) is patented proprietary software that is designed to adaptively achieve high throughput and transaction performance in a wide variety of network conditions, particularly those where TCP is perceived to be inefficient.
332
+ Checksum computation
333
+ TCP checksum for IPv4
334
+
335
+ When TCP runs over IPv4, the method used to compute the checksum is defined in RFC 793:
336
+
337
+ The checksum field is the 16 bit one's complement of the one's complement sum of all 16-bit words in the header and text. If a segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right with zeros to form a 16-bit word for checksum purposes. The pad is not transmitted as part of the segment. While computing the checksum, the checksum field itself is replaced with zeros.
338
+
339
+ In other words, after appropriate padding, all 16-bit words are added using one's complement arithmetic. The sum is then bitwise complemented and inserted as the checksum field. A pseudo-header that mimics the IPv4 packet header used in the checksum computation is shown in the table below.
340
+ TCP pseudo-header (IPv4) Bit offset 0–3 4–7 8–15 16–31
341
+ 0 Source address
342
+ 32 Destination address
343
+ 64 Zeros Protocol TCP length
344
+ 96 Source port Destination port
345
+ 128 Sequence number
346
+ 160 Acknowledgement number
347
+ 192 Data offset Reserved Flags Window
348
+ 224 Checksum Urgent pointer
349
+ 256 Options (optional)
350
+ 256/288+
351
+ Data
352
+
353
+
354
+ The source and destination addresses are those of the IPv4 header. The protocol value is 6 for TCP (cf. List of IP protocol numbers). The TCP length field is the length of the TCP header and data.
355
+ TCP checksum for IPv6
356
+
357
+ When TCP runs over IPv6, the method used to compute the checksum is changed, as per RFC 2460:
358
+
359
+ Any transport or other upper-layer protocol that includes the addresses from the IP header in its checksum computation must be modified for use over IPv6, to include the 128-bit IPv6 addresses instead of 32-bit IPv4 addresses.
360
+
361
+ A pseudo-header that mimics the IPv6 header for computation of the checksum is shown below.
362
+ TCP pseudo-header (IPv6) Bit offset 0 - 7 8–15 16–23 24–31
363
+ 0 Source address
364
+ 32
365
+ 64
366
+ 96
367
+ 128 Destination address
368
+ 160
369
+ 192
370
+ 224
371
+ 256 TCP length
372
+ 288 Zeros Next header
373
+ 320 Source port Destination port
374
+ 352 Sequence number
375
+ 384 Acknowledgement number
376
+ 416 Data offset Reserved Flags Window
377
+ 448 Checksum Urgent pointer
378
+ 480 Options (optional)
379
+ 480/512+
380
+ Data
381
+
382
+
383
+ Source address – the one in the IPv6 header
384
+ Destination address – the final destination; if the IPv6 packet doesn't contain a Routing header, TCP uses the destination address in the IPv6 header, otherwise, at the originating node, it uses the address in the last element of the Routing header, and, at the receiving node, it uses the destination address in the IPv6 header.
385
+ TCP length – the length of the TCP header and data
386
+ Next Header – the protocol value for TCP
387
+
388
+ Checksum offload
389
+
390
+ Many TCP/IP software stack implementations provide options to use hardware assistance to automatically compute the checksum in the network adapter prior to transmission onto the network or upon reception from the network for validation.
391
+ MESSAGE
392
+
393
+ payload = message * 87
394
+
395
+ puts "Publishing a message #{payload.bytesize} bytes in size"
396
+ exchange.publish(payload, :routing_key => queue.name)
397
+ }
398
+
399
+ t.join
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "bundler"
5
+ Bundler.setup
6
+
7
+ $:.unshift(File.expand_path("../../../lib", __FILE__))
8
+
9
+ require 'amqp'
10
+
11
+ if RUBY_VERSION == "1.8.7"
12
+ class Array
13
+ alias sample choice
14
+ end
15
+ end
16
+
17
+ puts "=> Handling message returns"
18
+ puts
19
+
20
+ AMQP.start(:host => '127.0.0.1') do |connection|
21
+ channel = AMQP.channel
22
+ channel.on_error { EM.stop; raise 'channel error' }
23
+
24
+ exchange = channel.fanout("amq.fanout")
25
+ exchange.on_return do |basic_return, header, payload|
26
+ puts "#{payload} was returned! reply_code = #{basic_return.reply_code}, reply_text = #{basic_return.reply_text}"
27
+ end
28
+
29
+ EventMachine.add_timer(0.3) {
30
+ 10.times do |i|
31
+ exchange.publish("Message ##{i}", :immediate => true)
32
+ end
33
+ }
34
+
35
+ EventMachine.add_timer(2) {
36
+ connection.close {
37
+ EventMachine.stop
38
+ }
39
+ }
40
+ end
@@ -225,7 +225,7 @@ module AMQP
225
225
 
226
226
  # only send channel.open when connection is actually open. Makes it possible to
227
227
  # do c = AMQP.connect; AMQP::Channel.new(c) that is what some people do. MK.
228
- @connection.on_open do
228
+ @connection.on_connection do
229
229
  self.open do |ch, open_ok|
230
230
  @channel_is_open_deferrable.succeed
231
231
 
@@ -51,22 +51,11 @@ module AMQP
51
51
  end # reconnect(force = false)
52
52
 
53
53
 
54
- # Defines a callback that will be executed when AMQP connection is considered open,
54
+ # Defines a callback that will be executed when AMQP connection is considered open:
55
55
  # after client and broker has agreed on max channel identifier and maximum allowed frame
56
- # size. You can define more than one callback.
56
+ # size and authentication succeeds. You can define more than one callback.
57
57
  #
58
- # @see #on_open
59
- # @api public
60
- def on_connection(&block)
61
- # defined here to make this method appear in YARD documentation. MK.
62
- super(&block)
63
- end # on_connection(&block)
64
-
65
- # Defines a callback that will be executed when AMQP connection is considered open,
66
- # before client and broker has agreed on max channel identifier and maximum allowed frame
67
- # size. You can define more than one callback.
68
- #
69
- # @see #on_connection
58
+ # @see #on_closed
70
59
  # @api public
71
60
  def on_open(&block)
72
61
  # defined here to make this method appear in YARD documentation. MK.
@@ -76,11 +65,12 @@ module AMQP
76
65
  # Defines a callback that will be run when broker confirms connection termination
77
66
  # (client receives connection.close-ok). You can define more than one callback.
78
67
  #
68
+ # @see #on_closed
79
69
  # @api public
80
- def on_disconnection(&block)
70
+ def on_closed(&block)
81
71
  # defined here to make this method appear in YARD documentation. MK.
82
72
  super(&block)
83
- end # on_disconnection(&block)
73
+ end # on_closed(&block)
84
74
 
85
75
  # Defines a callback that will be run when initial TCP connection fails.
86
76
  # You can define only one callback.
@@ -59,6 +59,12 @@ module AMQP
59
59
  #
60
60
  # @note This method, unlike EventMachine.run, DOES NOT block current thread.
61
61
  def self.run(&block)
62
+ if reactor_running?
63
+ EventMachine.run(&block)
64
+
65
+ return
66
+ end
67
+
62
68
  @eventmachine_thread ||= begin
63
69
  case self.server_type
64
70
  when :thin, :goliath, :evented_mongrel then
@@ -78,6 +84,8 @@ module AMQP
78
84
  t
79
85
  end
80
86
  end
87
+
88
+ @eventmachine_thread
81
89
  end # self.run
82
90
 
83
91
 
@@ -6,5 +6,5 @@ module AMQP
6
6
  #
7
7
  # @see AMQ::Protocol::VERSION
8
8
  # @return [String] AMQP gem version
9
- VERSION = '0.8.0.rc10'
9
+ VERSION = '0.8.0.rc11'
10
10
  end
@@ -7,7 +7,7 @@ describe "Authentication attempt" do
7
7
  # Environment
8
8
  #
9
9
 
10
- include EventedSpec::AMQPSpec
10
+ include EventedSpec::EMSpec
11
11
  include EventedSpec::SpecHelper
12
12
 
13
13
 
@@ -71,6 +71,22 @@ describe "Authentication attempt" do
71
71
  connection = AMQP.connect(:username => "amqp_gem", :password => Time.now.to_i.to_s, :vhost => "/amqp_gem_testbed", :on_possible_authentication_failure => handler)
72
72
  end # it
73
73
  end
74
+
75
+
76
+ context "and provided vhost DOES NOT EXIST" do
77
+ default_timeout 10
78
+
79
+ after(:all) { done }
80
+
81
+ it "fails" do
82
+ handler = Proc.new { |settings|
83
+ puts "Callback has fired"
84
+ callback_has_fired = true
85
+ done
86
+ }
87
+ connection = AMQP.connect(:username => "amqp_gem", :password => Time.now.to_i.to_s, :vhost => "/a/b/c/#{rand}/#{Time.now.to_i}", :on_possible_authentication_failure => handler)
88
+ end # it
89
+ end
74
90
  end # context
75
91
  end
76
92
 
@@ -21,7 +21,7 @@ describe "Message published as mandatory" do
21
21
  @channel = AMQP::Channel.new
22
22
  @channel.should be_open
23
23
 
24
- @exchange = @channel.fanout
24
+ @exchange = @channel.fanout("amqpgem.specs.#{Time.now.to_i}", :auto_delete => true, :durable => false)
25
25
  end
26
26
 
27
27
  after(:all) do
@@ -34,7 +34,7 @@ describe "Message published as mandatory" do
34
34
  it "is returned to the publisher via basic.return" do
35
35
  returned_messages = []
36
36
 
37
- @exchange.on_return do |basic_return|
37
+ @exchange.on_return do |basic_return, header, body|
38
38
  returned_messages << basic_return.reply_text
39
39
  end
40
40
  (1..10).to_a.each { |m| @exchange.publish(m, :immediate => true) }
metadata CHANGED
@@ -1,67 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: amqp
3
- version: !ruby/object:Gem::Version
4
- hash: 15424129
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0.rc11
5
5
  prerelease: 6
6
- segments:
7
- - 0
8
- - 8
9
- - 0
10
- - rc
11
- - 10
12
- version: 0.8.0.rc10
13
6
  platform: ruby
14
- authors:
7
+ authors:
15
8
  - Aman Gupta
16
9
  - Jakub Stastny aka botanicus
17
10
  - Michael S. Klishin
18
11
  autorequire:
19
12
  bindir: bin
20
13
  cert_chain: []
21
-
22
- date: 2011-05-12 00:00:00 Z
23
- dependencies:
24
- - !ruby/object:Gem::Dependency
14
+ date: 2011-05-14 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
25
17
  name: eventmachine
26
- prerelease: false
27
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &2156186280 !ruby/object:Gem::Requirement
28
19
  none: false
29
- requirements:
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- hash: 3
33
- segments:
34
- - 0
35
- version: "0"
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
36
24
  type: :runtime
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
39
- name: amq-client
40
25
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
26
+ version_requirements: *2156186280
27
+ - !ruby/object:Gem::Dependency
28
+ name: amq-client
29
+ requirement: &2156185780 !ruby/object:Gem::Requirement
42
30
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: -3702664442
47
- segments:
48
- - 0
49
- - 7
50
- - 0
51
- - alpha
52
- - 21
53
- version: 0.7.0.alpha21
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: 0.7.0.alpha23
54
35
  type: :runtime
55
- version_requirements: *id002
56
- description: Widely used, feature-rich asynchronous AMQP 0.9.1 client with batteries included
57
- email:
36
+ prerelease: false
37
+ version_requirements: *2156185780
38
+ description: Widely used, feature-rich asynchronous AMQP 0.9.1 client with batteries
39
+ included
40
+ email:
58
41
  - michael@novemberain.com
59
42
  - stastny@101ideas.cz
60
43
  executables: []
61
-
62
44
  extensions: []
63
-
64
- extra_rdoc_files:
45
+ extra_rdoc_files:
65
46
  - README.textile
66
47
  - docs/08Migration.textile
67
48
  - docs/Bindings.textile
@@ -77,7 +58,7 @@ extra_rdoc_files:
77
58
  - docs/RabbitMQVersions.textile
78
59
  - docs/Routing.textile
79
60
  - docs/VendorSpecificExtensions.textile
80
- files:
61
+ files:
81
62
  - .gitignore
82
63
  - .rspec
83
64
  - .travis.yml
@@ -116,6 +97,7 @@ files:
116
97
  - examples/error_handling/global_channel_level_exception_handler.rb
117
98
  - examples/error_handling/handling_authentication_failure_with_a_callback.rb
118
99
  - examples/error_handling/handling_authentication_failure_with_a_rescue_block.rb
100
+ - examples/error_handling/handling_vhost_misconfiguration_with_a_rescue_block.rb
119
101
  - examples/error_handling/tcp_connection_failure_handling_with_a_rescue_block.rb
120
102
  - examples/error_handling/tcp_connection_failure_with_a_callback.rb
121
103
  - examples/exchanges/declare_an_exchange_without_assignment.rb
@@ -135,6 +117,7 @@ files:
135
117
  - examples/guides/queues/12_deleting_a_queue.rb
136
118
  - examples/hello_world.rb
137
119
  - examples/hello_world_with_eventmachine_in_a_separate_thread.rb
120
+ - examples/hello_world_with_large_payload.rb
138
121
  - examples/legacy/ack.rb
139
122
  - examples/legacy/callbacks.rb
140
123
  - examples/legacy/clock.rb
@@ -146,6 +129,7 @@ files:
146
129
  - examples/legacy/primes.rb
147
130
  - examples/legacy/stocks.rb
148
131
  - examples/publishing/publishing_and_immediately_stopping_event_loop.rb
132
+ - examples/publishing/returned_messages.rb
149
133
  - examples/publishing/simplistic_scatter_gather.rb
150
134
  - examples/queues/automatic_binding_for_default_direct_exchange.rb
151
135
  - examples/queues/basic_get.rb
@@ -225,38 +209,73 @@ files:
225
209
  - tasks.rb
226
210
  homepage: http://github.com/ruby-amqp/amqp
227
211
  licenses: []
228
-
229
- post_install_message:
230
- rdoc_options:
212
+ post_install_message: ! "[\e[32mVersion 0.8.0\e[0m] [FEATURE] Returned messages, including
213
+ header & content via AMQP::Exchange#on_publish. Callback accepts 3 args: basic_return,
214
+ header, body\n[\e[32mVersion 0.8.0\e[0m] [BUG] Ruby 1.8.7-p249 is not supported
215
+ because of this (p249-specific) Ruby bug: http://bit.ly/iONBmH\n[\e[32mVersion 0.8.0\e[0m]
216
+ [FEATURE] AMQP::Utilities::EventLoopHelper detects app server (if any) being used
217
+ and starts EventMachine reactor in an optimal way.\n[\e[32mVersion 0.8.0\e[0m] [FEATURE]
218
+ AMQP 0.9.1 support, including tx.* operations class.\n[\e[32mVersion 0.8.0\e[0m]
219
+ [API] Default authentication handler now raises AMQP::PossibleAuthenticationFailureError\n[\e[32mVersion
220
+ 0.8.0\e[0m] [API] AMQP::Channel#initialize now takes 3rd (optional) options hash.\n[\e[32mVersion
221
+ 0.8.0\e[0m] [API] Broker connection class is now AMQP::Session.\n[\e[32mVersion
222
+ 0.8.0\e[0m] [API] AMQP::Error instance now may carry cause, an exception that caused
223
+ exception in question to be raised.\n[\e[32mVersion 0.8.0\e[0m] [API] When initial
224
+ TCP connection fails, default action is now to raise AMQP::TCPConnectionFailed.\n[\e[32mVersion
225
+ 0.8.0\e[0m] [API] AMQP::BasicClient#reconnect now takes 2nd optional argument, period
226
+ of waiting in seconds.\n[\e[32mVersion 0.8.0\e[0m] [FEATURE] Handlers for initial
227
+ connection failure, connection loss; channel-level exceptions handlers on Channel
228
+ instances.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Exchange#initialize now accepts
229
+ :arguments option that takes a hash.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Queue#initialize
230
+ now accepts :arguments option that takes a hash.\n[\e[32mVersion 0.8.0\e[0m] [API]
231
+ AMQP#Logger is deprecated. It will be removed before 1.0 release.\n[\e[32mVersion
232
+ 0.8.0\e[0m] [API] AMQP#fork is deprecated. It will be removed before 1.0 release.\n[\e[32mVersion
233
+ 0.8.0\e[0m] [API] AMQP::RPC is deprecated. It will be removed before 1.0 release.\n[\e[32mVersion
234
+ 0.8.0\e[0m] [FEATURE] Significant improvements to the documentation. From now on
235
+ lack of/poor documentation is considered a severe bug.\n[\e[32mVersion 0.8.0\e[0m]
236
+ [FEATURE] Support for RabbitMQ extensions to AMQP 0.9.1\n[\e[32mVersion 0.8.0\e[0m]
237
+ [API] AMQP::Exchange#publish now accepts (an optional) callback.\n[\e[32mVersion
238
+ 0.8.0\e[0m] [API] AMQP::Channel.new now accepts (an optional) callback.\n[\e[32mVersion
239
+ 0.8.0\e[0m] [API] AMQP::Header#ack now can acknowledge multiple deliveries\n[\e[32mVersion
240
+ 0.8.0\e[0m] [API] AMQP::Exchange#delete now takes (an optional) block that is called
241
+ when exchange.delete-ok response arrives.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Header
242
+ now implements #to_hash\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Queue#pop block
243
+ now can take 1, 2 or 3 arguments.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Queue#purge
244
+ \ now takes an optional block which is called when queue.purge-ok response arrives.\n[\e[32mVersion
245
+ 0.8.0\e[0m] [API] AMQP::Queue#delete now takes an optional block which is called
246
+ when queue.delete-ok response arrives.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Queue#delete
247
+ now accepts :nowait option.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Queue#unbind
248
+ now takes an optional block which is called when queue.unbind-ok response arrives.\n[\e[32mVersion
249
+ 0.8.0\e[0m] [API] AMQP::Queue#unbind now accepts :routing_key as alias to :key.
250
+ we believe it is a good idea to use AMQP terms.\n[\e[32mVersion 0.8.0\e[0m] [API]
251
+ AMQP::Channel#prefetch now takes (an optional) 2nd parameter that specifies that
252
+ QoS settings should be applied to underlying connection, as well as optional callback.\n[\e[32mVersion
253
+ 0.8.0\e[0m] [API] AMQP::Channel#recover now takes (an optional) callback that is
254
+ called when basic.recover-ok is received.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Frame
255
+ is gone.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Buffer is gone. Serialization &
256
+ framing are now handled primarily by amq-protocol.\n[\e[32mVersion 0.8.0\e[0m] [API]
257
+ AMQP::Queue#publish is deprecated.\n[\e[32mVersion 0.8.0\e[0m] [API] Name argument
258
+ for AMQP::Queue.new and Channel#queue is optional.\n"
259
+ rdoc_options:
231
260
  - --include=examples --main README.textile
232
- require_paths:
261
+ require_paths:
233
262
  - lib
234
- required_ruby_version: !ruby/object:Gem::Requirement
263
+ required_ruby_version: !ruby/object:Gem::Requirement
235
264
  none: false
236
- requirements:
237
- - - ">="
238
- - !ruby/object:Gem::Version
239
- hash: 3
240
- segments:
241
- - 0
242
- version: "0"
243
- required_rubygems_version: !ruby/object:Gem::Requirement
265
+ requirements:
266
+ - - ! '>='
267
+ - !ruby/object:Gem::Version
268
+ version: '0'
269
+ required_rubygems_version: !ruby/object:Gem::Requirement
244
270
  none: false
245
- requirements:
246
- - - ">"
247
- - !ruby/object:Gem::Version
248
- hash: 25
249
- segments:
250
- - 1
251
- - 3
252
- - 1
271
+ requirements:
272
+ - - ! '>'
273
+ - !ruby/object:Gem::Version
253
274
  version: 1.3.1
254
275
  requirements: []
255
-
256
276
  rubyforge_project: amqp
257
- rubygems_version: 1.8.2
277
+ rubygems_version: 1.8.1
258
278
  signing_key:
259
279
  specification_version: 3
260
280
  summary: AMQP client implementation in Ruby/EventMachine.
261
281
  test_files: []
262
-