Permalink
Browse files

Convert returned values of exchange.* functions

  • Loading branch information...
1 parent ebef5da commit b7063f1d36a7dc0d8791fb6716ffb90bcb0b50f7 Michael Klishin committed Feb 27, 2013
@@ -10,13 +10,14 @@
(ns langohr.exchange
"Exchanges are the entities to which messages are sent. Exchanges match and distribute messages across queues."
(:refer-clojure :exclude [declare])
- (:import [com.rabbitmq.client Channel AMQP$Exchange$DeclareOk AMQP$Exchange$DeleteOk AMQP$Exchange$BindOk]))
+ (:import [com.rabbitmq.client Channel AMQP$Exchange$DeclareOk AMQP$Exchange$DeleteOk AMQP$Exchange$BindOk]
+ [com.novemberain.langohr.exchange DeclareOk DeleteOk BindOk UnbindOk]))
;;
;; API
;;
-(defn ^AMQP$Exchange$DeclareOk declare
+(defn ^com.novemberain.langohr.exchange.DeclareOk declare
"Declares an exchange using exchange.declare AMQP method.
By default declares non-autodeleted non-durable exchanges.
@@ -36,31 +37,31 @@
:durable (default: false): indicates wether the exchange is durable. Information about Durable Exchanges is persisted and restored after server restart. Non-durable (transient) exchanges do not survive the server restart.
:internal (default: false): If set, the exchange may not be used directly by publishers, but only when bound to other exchanges. Internal exchanges are used to construct wiring that is not visible to applications."
([^Channel channel ^String name ^String type]
- (.exchangeDeclare channel name type))
+ (DeclareOk. (.exchangeDeclare channel name type)))
([^Channel channel ^String name ^String type &{:keys [durable auto-delete internal arguments] :or {durable false auto-delete false internal false}}]
- (.exchangeDeclare channel name type durable auto-delete internal arguments)))
+ (DeclareOk. (.exchangeDeclare channel name type durable auto-delete internal arguments))))
-(defn ^AMQP$Exchange$DeclareOk declare-passive
+(defn ^com.novemberain.langohr.exchange.DeclareOk declare-passive
"Performs a passive exchange declaration (checks if an exchange exists)"
[^Channel ch ^String name]
- (.exchangeDeclarePassive ch name))
+ (DeclareOk. (.exchangeDeclarePassive ch name)))
-(defn ^AMQP$Exchange$DeclareOk direct
+(defn ^com.novemberain.langohr.exchange.DeclareOk direct
"Shortcut method for declaring direct exchange by using exchange.declare AMQP method"
[^Channel channel ^String name & opts]
- (apply declare channel name "direct" opts))
+ (DeclareOk. (apply declare channel name "direct" opts)))
-(defn ^AMQP$Exchange$DeclareOk fanout
+(defn ^com.novemberain.langohr.exchange.DeclareOk fanout
"Shortcut method for declaring fanout exchange by using exchange.declare AMQP method"
[^Channel channel ^String name & opts]
- (apply declare channel name "fanout" opts))
+ (DeclareOk. (apply declare channel name "fanout" opts)))
-(defn ^AMQP$Exchange$DeclareOk topic
+(defn ^com.novemberain.langohr.exchange.DeclareOk topic
"Shortcut method for declaring topic exchange by using exchange.declare AMQP method"
[^Channel channel ^String name & opts]
- (apply declare channel name "topic" opts))
+ (DeclareOk. (apply declare channel name "topic" opts)))
-(defn ^AMQP$Exchange$DeleteOk delete
+(defn ^com.novemberain.langohr.exchange.DeleteOk delete
"Deletes an exchange using exchange.delete AMQP method. When an exchange is deleted all queue bindings on the exchange are cancelled.
Options:
@@ -72,18 +73,25 @@
"
([^Channel channel ^String name]
- (.exchangeDelete channel name))
+ (DeleteOk. (.exchangeDelete channel name)))
([^Channel channel ^String name if-unused]
- (.exchangeDelete channel name if-unused)))
+ (DeleteOk. (.exchangeDelete channel name if-unused))))
-(defn ^AMQP$Exchange$BindOk bind
- "Binds a queue to an exchange using exchange.bind AMQP method (a RabbitMQ-specific extension)
+(defn ^com.novemberain.langohr.exchange.BindOk bind
+ "Binds an exchange to another exchange using exchange.bind AMQP method (a RabbitMQ-specific extension)
Options:
:routing-key (default: \"\"): Specifies the routing key for the binding. The routing key is used for routing messages depending on the exchange configuration. Not all exchanges use a routing key - refer to the specific exchange documentation.
:arguments (default: nil): A hash of optional arguments with the declaration. Headers exchange type uses these metadata attributes for routing matching. In addition, brokers may implement AMQP extensions using x-prefixed declaration arguments."
([^Channel channel ^String destination ^String source]
- (.exchangeBind channel destination source ""))
- ([^Channel channel ^String destination ^String source &{ :keys [routing-key arguments] :or { routing-key "", arguments nil } }]
- (.exchangeBind channel destination source routing-key arguments)))
+ (BindOk. (.exchangeBind channel destination source "")))
+ ([^Channel channel ^String destination ^String source &{:keys [routing-key arguments] :or {routing-key ""}}]
+ (BindOk. (.exchangeBind channel destination source routing-key arguments))))
+
+(defn ^com.novemberain.langohr.exchange.UnbindOk unbind
+ "Unbinds an exchange from another exchange using exchange.unbind AMQP method (a RabbitMQ-specific extension)"
+ ([^Channel channel ^String destination ^String source ^String routing-key]
+ (UnbindOk. (.exchangeUnbind channel destination source routing-key)))
+ ([^Channel channel ^String destination ^String source &{:keys [arguments ^String routing-key]}]
+ (UnbindOk. (.exchangeUnbind channel destination source routing-key arguments))))
@@ -0,0 +1,35 @@
+package com.novemberain.langohr.exchange;
+
+import clojure.lang.IPersistentMap;
+import clojure.lang.PersistentHashMap;
+import com.novemberain.langohr.PersistentMapLike;
+import com.rabbitmq.client.AMQP;
+
+import java.util.HashMap;
+
+public class BindOk extends PersistentMapLike implements AMQP.Exchange.BindOk {
+ private final AMQP.Exchange.BindOk method;
+
+ public BindOk(AMQP.Exchange.BindOk method) {
+ this.method = method;
+
+ this.map = mapFrom(method);
+
+ }
+
+ public static IPersistentMap mapFrom(AMQP.Exchange.BindOk method) {
+ return PersistentHashMap.create(new HashMap());
+ }
+
+ public int protocolClassId() {
+ return method.protocolClassId();
+ }
+
+ public int protocolMethodId() {
+ return method.protocolMethodId();
+ }
+
+ public String protocolMethodName() {
+ return method.protocolMethodName();
+ }
+}
@@ -0,0 +1,35 @@
+package com.novemberain.langohr.exchange;
+
+import clojure.lang.IPersistentMap;
+import clojure.lang.PersistentHashMap;
+import com.novemberain.langohr.PersistentMapLike;
+import com.rabbitmq.client.AMQP;
+
+import java.util.HashMap;
+
+public class DeleteOk extends PersistentMapLike implements AMQP.Exchange.DeleteOk {
+ private final AMQP.Exchange.DeleteOk method;
+
+ public DeleteOk(AMQP.Exchange.DeleteOk method) {
+ this.method = method;
+
+ this.map = mapFrom(method);
+
+ }
+
+ public static IPersistentMap mapFrom(AMQP.Exchange.DeleteOk method) {
+ return PersistentHashMap.create(new HashMap());
+ }
+
+ public int protocolClassId() {
+ return method.protocolClassId();
+ }
+
+ public int protocolMethodId() {
+ return method.protocolMethodId();
+ }
+
+ public String protocolMethodName() {
+ return method.protocolMethodName();
+ }
+}
@@ -0,0 +1,35 @@
+package com.novemberain.langohr.exchange;
+
+import clojure.lang.IPersistentMap;
+import clojure.lang.PersistentHashMap;
+import com.novemberain.langohr.PersistentMapLike;
+import com.rabbitmq.client.AMQP;
+
+import java.util.HashMap;
+
+public class UnbindOk extends PersistentMapLike implements AMQP.Exchange.UnbindOk {
+ private final AMQP.Exchange.UnbindOk method;
+
+ public UnbindOk(AMQP.Exchange.UnbindOk method) {
+ this.method = method;
+
+ this.map = mapFrom(method);
+
+ }
+
+ public static IPersistentMap mapFrom(AMQP.Exchange.UnbindOk method) {
+ return PersistentHashMap.create(new HashMap());
+ }
+
+ public int protocolClassId() {
+ return method.protocolClassId();
+ }
+
+ public int protocolMethodId() {
+ return method.protocolMethodId();
+ }
+
+ public String protocolMethodName() {
+ return method.protocolMethodName();
+ }
+}

0 comments on commit b7063f1

Please sign in to comment.