11/*
2- * Copyright (c) 2017 Pivotal Software Inc, All Rights Reserved.
2+ * Copyright (c) 2017-2019 Pivotal Software Inc, All Rights Reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2121import java .util .Map ;
2222
2323/**
24- * Fluent API to specify the binding between an exchange and a queue.
24+ * Fluent API to specify the binding between AMQP resources.
25+ * Support exchange-to-queue and exchange-to-exchange binding definition.
2526 */
2627public class BindingSpecification {
2728
28- private String queue , exchange , routingKey ;
29+ private String queue , exchange , exchangeTo , routingKey ;
2930 private Map <String , Object > arguments ;
3031
3132 public static BindingSpecification binding () {
3233 return new BindingSpecification ();
3334 }
3435
36+ /**
37+ * Create an exchange-to-queue binding specification.
38+ *
39+ * @param exchange
40+ * @param routingKey
41+ * @param queue
42+ * @return
43+ */
3544 public static BindingSpecification binding (String exchange , String routingKey , String queue ) {
3645 return new BindingSpecification ().exchange (exchange ).routingKey (routingKey ).queue (queue );
3746 }
3847
48+ /**
49+ * Create an exchange-to-queue binding specification.
50+ *
51+ * @param exchange
52+ * @param routingKey
53+ * @param queue
54+ * @return
55+ * @since 1.4.1
56+ */
57+ public static BindingSpecification queueBinding (String exchange , String routingKey , String queue ) {
58+ return binding (exchange , routingKey , queue );
59+ }
60+
61+ /**
62+ * Creates an exchange-to-exchange binding specification.
63+ *
64+ * @param exchangeFrom
65+ * @param routingKey
66+ * @param exchangeTo
67+ * @return
68+ * @since 1.4.1
69+ */
70+ public static BindingSpecification exchangeBinding (String exchangeFrom , String routingKey , String exchangeTo ) {
71+ return new BindingSpecification ().exchangeFrom (exchangeFrom ).routingKey (routingKey ).exchangeTo (exchangeTo );
72+ }
73+
74+ /**
75+ * The queue to bind to.
76+ * <p>
77+ * Use this method for exchange-to-queue binding or
78+ * {@link #exchangeTo(String)} for exchange-to-exchange, but not both.
79+ *
80+ * @param queue
81+ * @return
82+ */
3983 public BindingSpecification queue (String queue ) {
4084 this .queue = queue ;
4185 return this ;
4286 }
4387
88+ /**
89+ * The exchange to bind from.
90+ * <p>
91+ * Alias of {@link #exchangeFrom(String)}. Usually used for
92+ * exchange-to-queue binding, but can be used for exchange-to-exchange
93+ * binding as well.
94+ *
95+ * @param exchange
96+ * @return
97+ * @see #exchangeFrom(String)
98+ * @see #exchangeTo(String)
99+ */
44100 public BindingSpecification exchange (String exchange ) {
45101 this .exchange = exchange ;
46102 return this ;
47103 }
48104
105+ /**
106+ * The exchange to bind from.
107+ * <p>
108+ * Alias of {@link #exchange(String)}. Usually used to make explicit
109+ * the definition is for an exchange-to-exchange binding, but works for
110+ * exchange-to-queue binding as well.
111+ *
112+ * @param exchangeFrom
113+ * @return
114+ * @see #exchange(String)
115+ * @see #exchangeTo(String)
116+ * @since 1.4.1
117+ */
118+ public BindingSpecification exchangeFrom (String exchangeFrom ) {
119+ this .exchange = exchangeFrom ;
120+ return this ;
121+ }
122+
123+ /**
124+ * The exchange to bind to.
125+ * <p>
126+ * Use this method for exchange-to-exchange binding or
127+ * {@link #queue(String)} for exchange-to-queue binding, but not both.
128+ *
129+ * @param exchangeTo
130+ * @return
131+ * @since 1.4.1
132+ */
133+ public BindingSpecification exchangeTo (String exchangeTo ) {
134+ this .exchangeTo = exchangeTo ;
135+ return this ;
136+ }
137+
138+ /**
139+ * The routing key for the binding.
140+ *
141+ * @param routingKey
142+ * @return
143+ */
49144 public BindingSpecification routingKey (String routingKey ) {
50145 this .routingKey = routingKey ;
51146 return this ;
52147 }
53148
149+ /**
150+ * Arguments of the binding. These are optional.
151+ *
152+ * @param arguments
153+ * @return
154+ */
54155 public BindingSpecification arguments (@ Nullable Map <String , Object > arguments ) {
55156 this .arguments = arguments ;
56157 return this ;
@@ -68,6 +169,10 @@ public String getRoutingKey() {
68169 return routingKey ;
69170 }
70171
172+ public String getExchangeTo () {
173+ return exchangeTo ;
174+ }
175+
71176 @ Nullable
72177 public Map <String , Object > getArguments () {
73178 return arguments ;
0 commit comments