Commit Graph

253 Commits

Author SHA1 Message Date
Matt Broadstone c113611b05 fix(QAmqpClient): simulate closeOk on forced disconnect 2015-11-19 17:03:55 -05:00
Stuart Longland fd1b19b3b6 QAmqpClient: Substitute static_cast for qobject_cast 2015-05-02 21:10:22 +10:00
Stuart Longland 60f680a4ef QAmqpChannelHash: Substitute static_cast for qobject_cast 2015-05-02 21:10:08 +10:00
Stuart Longland e43224877f QAmqpChannelHash: Store empty/null strings as null strings. 2015-05-02 21:02:50 +10:00
Stuart Longland c171b5c337 QAmqpChannelHash: Add contains function 2015-05-02 21:01:07 +10:00
Stuart Longland 3e5cf05256 QAmqpChannelHash: Coding style fixes. 2015-05-02 20:52:27 +10:00
Stuart Longland 2b707d53de QAmqpChannel: Emit closed signal when server closes.
When we initiate a Close, we get a CloseOk in response and on receipt of
the CloseOk, we mark the channel as closed and emit a signal to notify
everyone else.

Great.  Now what happens when the server closes the channel?  We emit a
CloseOk, then… nothing.  We do nothing.  This fixes this problem, moving
the notification/marking logic to a new function and calling that on
both Close (sent from server) and CloseOk.
2015-05-02 20:41:19 +10:00
Stuart Longland 31f90a17a0 QAmqpChannelHash: Tweak channelDestroyed.
- DON'T rely on sender()
- DON'T expect to be able to cast the QObject to a QAmqpChannel and have
  name() work.

This isn't as efficient as I'd like, but it doesn't crash either.
2015-04-13 08:28:09 +10:00
Stuart Longland ae4f1b336e QAmqpClient: Re-factor using QAmqpChannelHash. 2015-04-13 08:28:04 +10:00
Stuart Longland beb89b30b8 QAmqpChannelHash: Container for storing channels. 2015-04-13 08:27:57 +10:00
Stuart Longland 673274345c QAmqpClient: Fix 'does not have class type' error.
Something in the back of my mind had me thinking iterator.value was a
field not a function.  No idea why.  Fixed now.
2015-04-13 08:27:47 +10:00
Stuart Longland 6599fdbc63 QAmqpClient: Add garbage collection slot.
On 'destroyed', do a clean up of our exchanges and queues.
2015-04-13 08:27:41 +10:00
Stuart Longland bca3f5f8bd QAmqpClient: Fix attempt to assign const QString
How on earth did I expect that to work?  Morning cup of tea hasn't
kicked in yet, of course I can't assign a const QString passed by
reference.

Fix egregious PEBKAC-caused compile error.
2015-04-13 08:27:31 +10:00
Stuart Longland 2622a482b4 QAmqpClient: Store the nameless exchange too.
Since there will be probably many requests for that one.  If we're
passed in QString() instead of QString(""), we overwrite that with the
latter to ensure the name field is never NULL.
2015-04-13 08:27:02 +10:00
Stuart Longland fd4eaef364 QAmqpClient: Use QPointer to store exchanges and queues.
Just discovered you *CAN* delete them yourself safely, and one of the
tests does.  So best to not assume they'll get deleted by other parties.

QPointer takes care of this problem for us.
2015-04-13 08:26:37 +10:00
Stuart Longland ae77ff56e0 QAmqpClientPrivate: Store pointers to named queues and exchanges. 2015-04-13 08:26:20 +10:00
Matt Broadstone 943180da27 fix(multiple-consume): only send consume message once
Previously if multiple attempts to call consume were made, then
QAmqpQueue would send a frame for each of them leading to multiple
consumer tags and general confusion. This guards from calling
consume multiple times.
2015-04-07 14:30:18 -04:00
Gauthier Brion b27ba8cb64 Calling writeFrame with its static form 2015-03-16 16:27:23 +01:00
Gauthier Brion 2c330566e5 Allowing to configure the write timeout of AMQP frames 2015-03-16 15:03:23 +01:00
Matt Broadstone 9b3288ca9d only attempt to close socket if its open
On socket errors we always close the socket per amqp specification,
however there is no need to do so if the connection has already been
forcibly closed from the server side. This causes recursive loops
when using SSL connections
2015-03-05 15:18:03 -05:00
Matt Broadstone 6cc9ee7457 allow access to socket state, enable low latency options
Provides an accessor and change signal for the state of QAmqpClients
internal ssl socket. This also defaults the internal socket to low
latency mode, as well as keep alive.
2015-03-04 17:55:04 -05:00
Matt Broadstone a4bc1b5f4e show example of queued calls on QAmqpExchange
This gives an example of how you can use QMetaObject::invokeMethod to
call a QAmqpExchange from another thread. Also, moved the qRegisterMetaType
for QAmqpMessage::PropertyHash to the ctor of QAmqpClientPrivate
2015-02-27 09:13:17 -05:00
Matt Broadstone 4379e991c6 properly tune heartbeat delay
tuneOk was only properly tuning the heartbeat delay value for values
larger than the default delay sent by the server. This changes that
behavior to send back the requested heartbeat delay if one was provided
2015-02-27 08:16:22 -05:00
Matt Broadstone 3c2a039c08 convert methods to actions where it makes sense
QAmqpExchange and QAmqpQueue both have a number of actions associated
with them that should be defined as slots (especially for a potential
future where they are exported as QML objects). This is a step in the
direction of fully making these classes scriptable
2015-02-15 16:36:16 -05:00
Marcelo E. Magallon 2652206d18 Increment nextChannelNumber only once
nextChannelNumber is being incremented twice. When the counter wraps
around it starts declaring already existing channels and the AMQP server
disconnects the client. This patch doubles the number of channels that
can be created before this happens.
2015-02-11 16:13:27 -06:00
Marcelo E. Magallon 79226ccb35 Change channel id type to quint16
My reading of the spec is that channel numbers are unsigned.
2015-02-11 16:12:36 -06:00
Matt Broadstone 99b0d32f3f use sslConfiguration on socket
A public accessor and mutator was provided for using a QSslConfiguration
with a QAmqpClient, however the configuration was never actually assigned
to the internal socket. This patch fixes that, and removes the needless
storage of a copy of the QSslConfiguration as well
2015-02-09 21:30:23 -05:00
Matt Broadstone c4524b5204 update LICENSE and add license headers 2015-02-09 13:45:05 -05:00
Matt Broadstone 4640a9ad6a cleanup frame handlers on channel deletion
In cases where exchanges and queues are added and deleted during
an extended use of a QAmqpClient, the client should internally cleanup
the frame handlers registered for those objects. This patch does that
as well as providing two test cases verifying this behavior for both
QAmqpQueue and QAmqpExchange.
2015-02-06 16:12:58 -05:00
Matt Broadstone bcc6fdba9d provide access to QAbstractSocket error string on error
When a socket error occurs the string version of the error is now
stored in QAmqpClient's internal errorString variable, providing
access to the string to users of the client.
2015-02-05 10:40:59 -05:00
Matt Broadstone f5736a9615 rename UnroutableKey to NoRouteError 2015-02-04 19:59:57 -05:00
Gauthier Brion 7cd07f4983 Fix problem of ms vs seconds for heartbeat 2015-02-03 18:00:26 +01:00
Matt Broadstone 31d8affc84 add support for ssl connections
This adds preliminary support for SSL connections to a RabbitMQ
server. Instead of providing two clients (QAmqpClient/QAmqpSslClient),
the SSL support was directly rolled into QAmqpClient itself, providing
signals/slots to deal with errors (sslErrors/ignoreSslErrors), and
the ability to assign a QSslConfiguration. Travis testing for ssl
support is currently disabled, pending a solution to a travis
limitation for starting ssl listeners
2015-02-02 10:49:25 -05:00
Matt Broadstone d051f5a445 add support for Basic.Reject
This adds the reject method to QAmqpQueue in order to reject an
incoming message, and conditionally requeue it.
2015-02-01 09:50:32 -05:00
Matt Broadstone e6b69010e4 remove QAmqpSslClient
Since you can provide amqps endpoints, it makes no sense to have a
separate class for SSL client support. This functionality will be
merged directly into QAmqpClient
2015-01-31 12:57:26 -05:00
Matt Broadstone 009c3131f5 add two new properties, changed the name of one
QAmqpQueue and QAmqpExchange both now have an isDeclared property,
and QAmqpChannel::isOpened was renamed to isOpen to more closely follow
Qt style/api guidelines
2015-01-31 12:44:25 -05:00
Matt Broadstone bb13e2e830 initialize timeout to 0 for autoReconnect
Previously timeout was initialized to -1, which meant when it went
through delay loops it would always use a negative value. This closes
issue #9
2015-01-29 18:57:11 -05:00
Matt Broadstone f2ac01de34 add preliminary support for publisher acknowledgements
RabbitMQ supports publish confirms (Publisher Acknowledgements) on
a given channel. This enables the user to toggle this functionality
and ensure that published messages are in fact published.
2015-01-19 13:51:20 -05:00
Matt Broadstone 8be77044ef micro optimizations
These are paths that we can optimize for since they are unlikely
to occur.
2015-01-15 07:27:19 -05:00
Matt Broadstone f35e939446 Add coveralls support to travis builds 2014-09-16 17:42:21 -04:00
Matt Broadstone 98f40f5589 Forward socket errors to user
Provide accessors and a signal for socket errors, so that the user
can react accordingly. This closes issue #6
2014-09-16 11:55:36 -04:00
Matt Broadstone 7242a64a2f clean up QAmqpFrame paths
- opt for QDataStream overloads instead of read ctor and toStream methods
- removed some unneccesary prefixes to Type and MethodClass enums
- removed documentation from header (this is coming back!)
- cleaned up some confusing code paths, removed unneccessary methods (like readHeader/writeHeader)
2014-09-15 15:45:20 -04:00
Matt Broadstone 10ab1423c2 remove QAMQP namespace
This is a very small library, so there is no real pressing need for
a library namespace. Further, the namespacing actually makes it rather
difficult to work with in some cases. Opting for a more "Qt" style
class naming scheme, using the QAmqp class prefix
2014-09-15 13:26:48 -04:00
Matt Broadstone 9887fa2333 rpath improvements
Improve on the previous commit adding QMAKE_RPATHDIR. We can now use
rpath for out-of-source builds, as well as on osx.
2014-09-13 18:28:05 -04:00
Adam Majer 1eea37cb6f cleanup frame processing and payload alignment
- remove a level of indentation making frame processing easier to read
- use qFromBigEndian(const uchar *src) to ensure alignment of payload size
2014-09-12 20:39:43 -04:00
Adam Majer 7ff0dfab1b Use stack instead of broken usage of QByteBuffer
The internal buffer should not be used blindly when reading
Frame::HEADER_SIZE, as it is error prone and adds nothing over reading
on the stack (and it's only 7 bytes). There are places in this class
where buffer.clear() is called.
2014-09-12 13:15:52 -04:00
Matt Broadstone 4bfef5f81f initially reserve HEADER_SIZE for buffer 2014-09-12 08:22:04 -04:00
Matt Broadstone dab2cfe08f fix parsing of connection strings with default vhost
We should assume that a trailing slash at the end of a connection
URI means to use the default vhost of /. This fixes issue #2.
2014-09-12 08:15:34 -04:00
Matt Broadstone d7dbcb892c add swap and move support for QAMQP::Message
- declared typeinfo as Q_MOVABLE_TYPE
- declared message as shared
2014-09-11 16:29:34 -04:00
Matt Broadstone 7e151dfc7b fix windows build
- add equality operator to QAMQP::Message
- add qHash for QAMQP::Message... because MSVC
2014-09-11 15:37:46 -04:00
Matt Broadstone 84746ff77c handle messages with empty payloads
If a message is delivered with an empty body, we were not previously
enqueuing the message. This fixes issue #43
2014-09-10 22:39:13 -04:00
Matt Broadstone 6a3d355de2 rename amqp_ files to qamqp
amqp_<filename> is used in at least two other C/C++ projects related
to amqp, so this commit changes all our source to use a qamqp header.
This avoids potential clashes, and is more in line with Qt style
2014-08-26 15:05:39 -04:00
Matt Broadstone 840efb037d refactor Frame::Content to use Message::Property 2014-08-26 14:45:50 -04:00
Matt Broadstone bdd9bae8ea refactor ValueType
moved ValueType from the QAMQP namespace to QAMQP::MetaType namespace
to avoid clashes with very generic enum strings
2014-08-26 14:02:43 -04:00
Matt Broadstone 0ccb3035cd move QAMQP::Frame to private API
QAMQP::Frame used to be public API mostly for MessageProperties. There
is no longer a need to keep this API public, as it should all be wrapped
with the cleaner Message/Queue/Exchange/Client API set
2014-08-26 09:57:08 -04:00
Matt Broadstone 0bc1c32bd8 add test for sharing a channel
Though it's not necessarily recommended (per spec), Channels can be
shared by multiple Exchanges and Queues. I've added a test here showing
that's possible with QAMQP
2014-08-08 17:09:52 -04:00
Matt Broadstone 870af7b5d4 split channel tests into their own executable
Refactored tests specific to QAMQP::Channel into its own full test
case, as there are more on the way
2014-08-08 17:09:51 -04:00
Matt Broadstone baa5c1de3e refactor Channel::channelClose to just Channel::close 2014-08-08 17:09:51 -04:00
Matt Broadstone 695f7d2997 complete close handshakes properly for Client and Channel
We had frame handlers for Close messages from the server, but were not
doing our due diligence and sending a corresponding CloseOk back to the
server after processing. It seems RabbitMQ is generous in this case, but
at least we're doing it the right way now
2014-08-07 14:12:28 -04:00
Matt Broadstone 1ebe3bd667 implement flow frame handling support
Fleshed out the previously unimplemented flow control frame handling,
added an auto test for it. Also refactored out the stateChanged ChannelPrivate
method, if we need proper state support in the future it will be added with
a better implementation
2014-08-07 13:52:09 -04:00
Matt Broadstone 6291bb7f42 add auto test for channel close
improve code coverage for tests by including a test for Channel::closeChannel
to both Exchange and Queue test suites
2014-08-06 22:35:46 -04:00
Matt Broadstone bb2e9881ea short strings are latin1 encoded not utf8 2014-08-05 15:45:25 -04:00
Matt Broadstone 3ce39c273f use compatible type max definitions
UINT8_MAX/UINT16_MAX only work on osx and glibc builds with certain
defines.
2014-08-05 15:28:19 -04:00
Matt Broadstone fdb8dddc14 initialize network variables
there were a number of variables copied over from the legacy Network
class that were not properly initialized.
2014-08-05 14:38:13 -04:00
Matt Broadstone d5cc6258c6 refactor type handling in QAMQP
There are two distinctive type sets in AMQP, the basic AMQP types
and then the superset of Table value types. This commit attempts to
make that distinction more clear by the addition of a Table class.
Basically, AMQP value type read/write support is left in Frame for the
time being, while table value field read/write support has been moved
to the Table class. Also, a number of type differences exist between
the spec and rabbitmq's binary parser (noted in the errata page) which
were not previously honored.
2014-08-05 14:34:12 -04:00
Matt Broadstone 4ea3bdb851 don't store content message in Content frame
the message was being needlessly duplicated into the Content frame,
now we only store the size there to be sent out, rather than the whole
message

remove QAMQP prefix in authenticator
2014-08-05 14:34:03 -04:00
Matt Broadstone 77134f0279 frame cleanup
removed crufty code, improve test coverage
2014-07-29 13:35:01 -04:00
Matt Broadstone 1083f4db3a test delayed queue bindings
improve code coverage by adding a test for delayed declaration and
bindings of queues. also uncovered a bug with disconnectFromHost in
Client
2014-07-29 12:57:15 -04:00
Matt Broadstone 75f7882d1c update flakey get test 2014-07-28 17:55:30 -04:00
Matt Broadstone fa132d7c72 guarantee frames are written
wait for the END frame to be written, guaranteeing that data will
be written when you think it has been.
2014-07-28 11:36:52 -04:00
Matt Broadstone 5d00b2a068 add accessors for custom headers
Moved from direct access to a Frame::TableField to accesors to that
data. More readable/useable api for this data.
2014-07-21 17:08:13 -04:00
Matt Broadstone 5c6cd23e10 move property definition/access to Message
MessageProperties is currently defined in Frame::Content, which makes it
cumbersome to use when working directly with a Message itself. I attempted
to make this easier by using typedefs, but it's become pretty obvious that
it belongs in the Message class itself.
2014-07-21 16:54:12 -04:00
Matt Broadstone dec9ef72d3 added test for invalid routing keys
also added a debug message for attempts to write shortstr's greater
than acceptable length.
2014-06-30 18:42:39 -04:00
Matt Broadstone a89dbb3805 add tests for proper uri validation
this is the missing component from PR #41, tests a number of example
amqp uri's provided by the RabbitMQ spec/documentation
2014-06-26 16:05:47 -04:00
Matt Broadstone 12a03f959f add qos support to channel
AMQP Basic qos support added to Channel class. There is an option
for global qos which is currently not added. Also, added auto tests
for qos definition, proper qos operation and verifying that RabbitMQ
does not support prefetchSize.
2014-06-26 10:28:58 -04:00
Matt Broadstone 824d8d56ca add PR #41
vhosts can't start with a /
2014-06-24 21:35:58 -04:00
Matt Broadstone b662fd6557 fix issue #33
AMQP_BASIC_CONTENT_ENCODING_FLAG and AMQP_BASIC_MESSAGE_ID_FLAG were
switched
2014-06-24 21:26:22 -04:00
Matt Broadstone e94f372cfe clean up QAMQP::Queue api
removed noAck as it relates only to the synchronous get AMQP api
moved noAck to get method
applied visual separation in headers between AMQP Queue and AMQP Basic methods
2014-06-24 21:09:45 -04:00
Matt Broadstone cab23c97cc add support for cancelling a consumer
cancel method and cancelled signal added to Queue, added auto tests
to guarantee conditions surrounding the cancel process
2014-06-24 11:09:19 -04:00
Matt Broadstone c43c2d6788 ensure consuming only occurs once per queue
a Queue can act as a consumer in QAMQP, but previously we did no checks
to ensure that a Queue sent a request to consume only once. This commit
adds API for checking and ensuring that this is the case. Also, I reverted
the changes to allow multiple consumer tags because this was incorrect.
Also included is a new signal "consuming" to notify when consumption occurs,
and auto tests have been updated to use this, as well as verify that it
can only occur once per-consumer
2014-06-24 10:30:05 -04:00
Matt Broadstone 4f808bef92 add publish options
- add publish options to Exchange (these need to move to a Basic abstraction)
- listen for bmReturn in Exchange to catch errors
- added auto tests to check behavior of an invalid mandatory publish
- cleaned up bit fields in exchange and queue
2014-06-23 15:36:03 -04:00
Matt Broadstone cb52911bed additional peer exceptions added
added a few cases where we should be raising peer exceptions when
delivered invalid frames from the server (per spec)
2014-06-19 13:36:11 -04:00
Matt Broadstone 1ae43ef4bd change the way messages are received
Messages used to be "delivered" and pushed right onto the queue, which
is where the requirement for Message to be explicitly shared came from.
Now messages that are incomplete come in and are stored in a "currentMessage"
private member (there is a requirement that messages are delivered in this
fashion, by the spec). Once the message body has come in, it is put into
the local queue and the messageReceived signal is emitted.

Also, modified Queue to be able to track a number of consumer tags. This
was exposed by the "routing" tutorial, where a single consumer can bind
to a number of exchanges with a generated consumer tag. The previous example
did not run into this problem because it used an explicitly set consumer tag
and therefore there were no conflicts.
2014-06-19 10:01:47 -04:00
Matt Broadstone bf21ebc246 refactor Message
message now provides an "isValid" property, data is implicitly shared now
2014-06-19 10:00:52 -04:00
Matt Broadstone b5d77e17e3 revert reordering publish arguments
I originally changed the publishing arguments to take a routingKey first
which is pretty nonstandard across implementations. Reverting for
conformity.
2014-06-17 15:14:23 -04:00
Matt Broadstone 352669f392 added all tests around exchange declaration 2014-06-11 15:49:05 -04:00
Matt Broadstone 4a09094140 added autotest for invalid exchange declarations 2014-06-11 14:38:42 -04:00
Matt Broadstone 496e00abb9 move error constants to global namespace 2014-06-11 13:44:30 -04:00
Matt Broadstone c2dad7d6bb added RemoveOptions to Exchange, remove auto deletion (this should be handled by the AutoDelete option), and added
a test for an invalid remove(roIfUnused)
2014-06-10 21:41:28 -04:00
Matt Broadstone 8e2b66677d add roForce to Queue, replace forceRemove 2014-06-10 21:27:59 -04:00
Matt Broadstone 566de2e4d4 spelling cleanups 2014-06-10 21:23:08 -04:00
Matt Broadstone 46e974aeb8 provide purged signal, other small cleanups 2014-06-10 13:04:57 -04:00
Matt Broadstone 4ff7683536 standardize MessageProperties throughout codebase 2014-06-10 09:16:04 -04:00
Matt Broadstone 4422924219 convert QAMQP::Queue to a proper QQueue subclass, move MessageProperties to QAMQP namespace 2014-06-10 09:05:42 -04:00
Matt Broadstone 55da181788 a little closer to proper tuning 2014-06-09 19:39:09 -04:00
Matt Broadstone 1510e1f6c6 provide access to tuning variables, add checks for frameMax per spec in a number of areas,
add an incomplete autotest for using connection tuning parameters
2014-06-09 19:27:24 -04:00
Matt Broadstone 223af56683 use consistent naming scheme for constants 2014-06-09 19:26:30 -04:00
Matt Broadstone 1d3f53ba60 clear buffer on forced disconnect, fatal disconnect on bad frame end, store tuning parameters 2014-06-09 16:01:23 -04:00
Matt Broadstone 613bd5ba96 make sure all errors have Error in the name 2014-06-09 15:10:22 -04:00
Matt Broadstone 50a588e678 allow for creation of a queue with no name, added auto test for validation 2014-06-09 14:07:13 -04:00