Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix headers exchange #19

Merged
merged 2 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/src/client/impl/exchange_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class _ExchangeImpl implements Exchange {
}

void publish(Object message, String routingKey, { MessageProperties properties, bool mandatory : false, bool immediate : false}) {
if (!type.isCustom && type != ExchangeType.FANOUT && (routingKey == null || routingKey.isEmpty)) {
if (!type.isCustom && type != ExchangeType.FANOUT && type != ExchangeType.HEADERS && (routingKey == null || routingKey.isEmpty)) {
throw new ArgumentError("A valid routing key needs to be specified");
}

Expand All @@ -37,8 +37,8 @@ class _ExchangeImpl implements Exchange {
}

Future<Consumer> bindPrivateQueueConsumer(List<String> routingKeys, {String consumerTag, bool noAck: true}) {
// Fanout exchanges do not need to specify any keys. Use the default one if none is specified
if (type == ExchangeType.FANOUT && (routingKeys == null || routingKeys.isEmpty)) {
// Fanout and headers exchanges do not need to specify any keys. Use the default one if none is specified
if ((type == ExchangeType.FANOUT || type == ExchangeType.HEADERS) && (routingKeys == null || routingKeys.isEmpty)) {
routingKeys = [""];
}

Expand Down
14 changes: 8 additions & 6 deletions lib/src/client/impl/queue_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class _QueueImpl implements Queue {
if (exchange == null) {
throw new ArgumentError("Exchange cannot be null");
}
// Fanout exchanges do not need to specify any keys. Use the default one if none is specified
// Fanout and headers exchanges do not need to specify any keys. Use the default one if none is specified
if (routingKey == null || routingKey.isEmpty) {
if (exchange.type == ExchangeType.FANOUT) {
if (exchange.type == ExchangeType.FANOUT || exchange.type == ExchangeType.HEADERS) {
routingKey = "";
} else {
throw new ArgumentError("A routing key needs to be specified to bind to this exchange type");
Expand All @@ -56,7 +56,8 @@ class _QueueImpl implements Queue {
..queue = name
..exchange = exchange.name
..routingKey = routingKey
..noWait = noWait;
..noWait = noWait
..arguments = arguments;

Completer<Queue> completer = new Completer<Queue>();
channel.writeMessage(bindRequest, completer : completer, futurePayload : this);
Expand All @@ -67,9 +68,9 @@ class _QueueImpl implements Queue {
if (exchange == null) {
throw new ArgumentError("Exchange cannot be null");
}
// Fanout exchanges do not need to specify any keys. Use the default one if none is specified
// Fanout and headers exchanges do not need to specify any keys. Use the default one if none is specified
if (routingKey == null || routingKey.isEmpty) {
if (exchange.type == ExchangeType.FANOUT) {
if (exchange.type == ExchangeType.FANOUT || exchange.type == ExchangeType.HEADERS) {
routingKey = "";
} else {
throw new ArgumentError("A routing key needs to be specified to unbind from this exchange type");
Expand All @@ -80,7 +81,8 @@ class _QueueImpl implements Queue {
..reserved_1 = 0
..queue = name
..exchange = exchange.name
..routingKey = routingKey;
..routingKey = routingKey
..arguments = arguments;

Completer<Queue> completer = new Completer<Queue>();
channel.writeMessage(unbindRequest, completer : completer, futurePayload : this);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/client/queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class Queue {
/**
* Bind this queue to [exchange] using [routingKey] and return a [Future<Queue>] to the bound queue.
*
* The [routingKey] parameter cannot be empty or null unless [exchange] is of type [ExchangeType.FANOUT].
* The [routingKey] parameter cannot be empty or null unless [exchange] is of type [ExchangeType.FANOUT] or [ExchangeType.HEADERS].
* For any other [exchange] type, passing an empty or null [routingKey] will cause an [ArgumentError]
* to be thrown.
*/
Expand All @@ -46,7 +46,7 @@ abstract class Queue {
/**
* Unbind this queue from [exchange] with [routingKey] and return a [Future<Queue>] to the unbound queue.
*
* The [routingKey] parameter cannot be empty or null unless [exchange] is of type [ExchangeType.FANOUT].
* The [routingKey] parameter cannot be empty or null unless [exchange] is of type [ExchangeType.FANOUT] or [ExchangeType.HEADERS].
* For any other [exchange] type, passing an empty or null [routingKey] will cause an [ArgumentError]
* to be thrown.
*/
Expand Down