zainali5120
2021-03-17 cbcbaa6a1e96982b73091b0ac8927fafa27c6a39
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
package com.xcong.excoin.configurations;
 
import com.xcong.excoin.configurations.properties.CustomRabbitProperties;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
 
import javax.annotation.Resource;
 
/**
 * @author wzy
 * @date 2020-05-25
 **/
@Configuration
public class RabbitMqConfig {
 
    public static final String EXCHANGE_ONE = "biue-exchange-one";
 
    public static final String QUEUE_TEST = "test-queue";
 
    public static final String ROUTING_KEY_TEST = "test-routingKey";
 
    public static final String EXCHANGE_A = "biue-exchange-A";
 
 
    public static final String EXCHANGE_USDT_UPDATE = "exchange_usdt_update";
 
    public static final String QUEUE_USDT_UPDATE = "queue_usdt_update";
 
    public static final String ROUTING_KEY_USDT_UPDATE = "routing_key_usdt_update";
 
    public static final String EXCHANGE_USDT_ADDRESS = "exchange_usdt_address";
 
    public static final String QUEUE_USDT_ADDRESS= "queue_usdt_address";
 
    public static final String ROUTING_KEY_USDT_ADDRESS = "routing_key_usdt_address";
 
 
    /**
     * 撮合交易
     */
    public static final String EXCHANGE_B = "biue-exchange-B";
 
 
    // 开多止盈队列
    public static final String QUEUE_MOREPRO = "QUEUE_MOREPRO_NEW";
    // 开空止盈队列
    public static final String QUEUE_LESSPRO = "QUEUE_LESSPRO_NEW";
    // 开多止损队列
    public static final String QUEUE_MORELOSS = "QUEUE_MORELOSS_NEW";
    // 开空止损队列
    public static final String QUEUE_LESSLOSS = "QUEUE_LESSLOSS_NEW";
 
    // 限价委托
    public static final String QUEUE_LIMIT = "QUEUE_LIMIT_NEW";
 
    // 委托平仓
    public static final String QUEUE_LIMIT_CLOSE = "QUEUE_LIMIT_CLOSE_NEW";
 
    // 爆仓队列
    public static final String QUEUE_COINOUT = "QUEUE_COINOUT_NEW";
 
    //价格操作
    public static final String QUEUE_PRICEOPERATE = "QUEUE_PRICEOPERATE_NEW";
 
    // 平仓队列
    public static final String QUEUE_CLOSETRADE = "QUEUE_CLOSETRADE_NEW";
 
    // 全仓爆仓
    public static final String QUEUE_WHOLE_BOMB = "QUEUE_WHOLE_BOMB_NEW";
 
    // 全仓价格操作
    public static final String QUEUE_WHOLE_PRICE = "QUEUE_WHOLE_PRCE";
 
    // 跟单下单
    public static final String QUEUE_FOLLOW_ORDER = "QUEUE_FOLLOW_ORDER";
 
    public static final String ROUTINGKEY_FOLLOW_ORDER = "ROUTINGKEY_FOLLOW_ORDER";
 
    // 开多止盈路由键
    public static final String ROUTINGKEY_MOREPRO = "ROUTINGKEY_MOREPRO";
    // 开空止盈路由
    public static final String ROUTINGKEY_LESSPRO = "ROUTINGKEY_LESSPRO";
    // 开多止损路由
    public static final String ROUTINGKEY_MORELOSS = "ROUTINGKEY_MORELOSS";
    // 开空止损路由
    public static final String ROUTINGKEY_LESSLOSS = "ROUTINGKEY_LESSLOSS";
    // 限价委托
    public static final String ROUTINGKEY_LIMIT = "ROUTINGKEY_LIMIT";
 
    // 爆仓路由
    public static final String ROUTINGKEY_COINOUT = "ROUTINGKEY_COINOUT";
 
 
    // 价格操作
    public static final String ROUTINGKEY_PRICEOPERATE = "ROUTINGKEY_PRICEOPERATE";
    // 平仓路由
    public static final String ROUTINGKEY_CLOSETRADE = "ROUTINGKEY_CLOSETRADE";
 
    // 委托平仓
    public static final String ROUTINGKEY_LIMIT_CLOSE = "ROUTINGKEY_LIMIT_CLOSE";
 
    // 全仓爆仓
    public static final String ROUTINGKEY_WHOLE_BOMB = "ROUTINGKEY_WHOLE_BOMB";
 
    // 全仓价格操作
    public static final String ROUTINGKEY_WHOLE_PRICE = "ROUTINGKEY_WHOLE_PRICE";
 
    @Resource
    private ConnectionFactory connectionFactory;
 
//    @Bean
//    public ConnectionFactory connectionFactory() {
//        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(customRabbitProperties.getHost(), customRabbitProperties.getPort());
//        connectionFactory.setUsername(customRabbitProperties.getUsername());
//        connectionFactory.setPassword(customRabbitProperties.getPassword());
//        connectionFactory.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.CORRELATED);
//        return connectionFactory;
//    }
 
    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public RabbitTemplate rabbitTemplate() {
        return new RabbitTemplate(connectionFactory);
    }
 
    @Bean
    public DirectExchange defaultExchange() {
        return new DirectExchange(EXCHANGE_ONE);
    }
 
    @Bean
    public Queue testQueue() {
        return new Queue(QUEUE_TEST, true);
    }
 
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(testQueue()).to(defaultExchange()).with(ROUTING_KEY_TEST);
    }
 
 
   @Bean
    public DirectExchange usdtUpdateExchange() {
        return new DirectExchange(EXCHANGE_USDT_UPDATE);
    }
 
 
    @Bean
    public Queue usdtUpdateQueue() {
        return new Queue(QUEUE_USDT_UPDATE, true);
    }
 
    @Bean
    public Binding usdtUpdatebinding() {
        return BindingBuilder.bind(usdtUpdateQueue()).to(usdtUpdateExchange()).with(ROUTING_KEY_USDT_UPDATE);
    }
 
    @Bean
    public DirectExchange usdtAddressExchange() {
        return new DirectExchange(EXCHANGE_USDT_ADDRESS);
    }
 
 
    @Bean
    public Queue usdtAddressQueue() {
        return new Queue(QUEUE_USDT_ADDRESS, true);
    }
 
    @Bean
    public Binding usdtAddressbinding() {
        return BindingBuilder.bind(usdtAddressQueue()).to(usdtAddressExchange()).with(ROUTING_KEY_USDT_ADDRESS);
    }
 
 
    /**
     * 交换器A 可以继续添加交换器B C
     *
     * @return
     */
    @Bean
    public DirectExchange orderExchange() {
        return new DirectExchange(EXCHANGE_A);
    }
 
 
    /**
     * 开多止盈队列
     *
     * @return
     */
    @Bean
    public Queue queueMorePro() {
        // 定义一个名称为QUEUE_A,持久化的队列
        return new Queue(QUEUE_MOREPRO, true);
    }
 
    /**
     * 开空止盈队列
     *
     * @return
     */
    @Bean
    public Queue queueLessPro() {
        // 定义一个名称为QUEUE_A,持久化的队列
        return new Queue(QUEUE_LESSPRO, true);
    }
 
    /**
     * 开多止损
     *
     * @return
     */
    @Bean
    public Queue queueMoreLoss() {
        // 定义一个名称为QUEUE_A,持久化的队列
        return new Queue(QUEUE_MORELOSS, true);
    }
 
    /**
     * 开空止损
     *
     * @return
     */
    @Bean
    public Queue queueLessLoss() {
        // 定义一个名称为QUEUE_A,持久化的队列
        return new Queue(QUEUE_LESSLOSS, true);
    }
 
    /**
     * 限价委托
     *
     * @return
     */
    @Bean
    public Queue queueLimit() {
        return new Queue(QUEUE_LIMIT, true);
    }
 
    /**
     * 委托平仓
     *
     * @return
     */
    @Bean
    public Queue queueLimitClose() {
        return new Queue(QUEUE_LIMIT_CLOSE, true);
    }
 
 
    /**
     * 爆仓
     *
     * @return
     */
    @Bean
    public Queue queueCoinout() {
        return new Queue(QUEUE_COINOUT, true);
    }
 
    /**
     * 价格操作
     *
     * @return
     */
    @Bean
    public Queue queuePriceoperate() {
        return new Queue(QUEUE_PRICEOPERATE, true);
    }
 
    /**
     * 价格操作
     *
     * @return
     */
    @Bean
    public Queue queueCloseTrade() {
        return new Queue(QUEUE_CLOSETRADE, true);
    }
 
    @Bean
    public Queue queueWholePrice() {
        return new Queue(QUEUE_WHOLE_PRICE, true);
    }
    /**
     * 全仓爆仓
     * @return
     */
    @Bean
    public Queue queueWholeBomb() {
        return new Queue(QUEUE_WHOLE_BOMB, true);
    }
 
    @Bean
    public Queue queueFollowOrder() {
        return new Queue(QUEUE_FOLLOW_ORDER, true);
    }
 
    @Bean
    public Binding bindingFollowOrder() {
        return BindingBuilder.bind(queueFollowOrder()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_FOLLOW_ORDER);
    }
 
 
    @Bean
    public Binding bindingWholePrice() {
        return BindingBuilder.bind(queueWholePrice()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_WHOLE_PRICE);
    }
 
    /**
     * 开多止盈
     *
     * @return
     */
    @Bean
    public Binding bindingMroPro() {
        return BindingBuilder.bind(queueMorePro()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_MOREPRO);
    }
 
    /**
     * 开空止盈
     *
     * @return
     */
    @Bean
    public Binding bindingLessPro() {
        return BindingBuilder.bind(queueLessPro()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_LESSPRO);
    }
 
    /**
     * 开多止损
     *
     * @return
     */
    @Bean
    public Binding bindingMroLoss() {
        return BindingBuilder.bind(queueMoreLoss()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_MORELOSS);
    }
 
    /**
     * 开空止损
     *
     * @return
     */
    @Bean
    public Binding bindingLessLoss() {
        return BindingBuilder.bind(queueLessLoss()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_LESSLOSS);
    }
 
 
    /**
     * 委托
     *
     * @return
     */
    @Bean
    public Binding bindingLimit() {
        return BindingBuilder.bind(queueLimit()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_LIMIT);
    }
 
    /**
     * 委托平仓
     *
     * @return
     */
    @Bean
    public Binding bindingLimitClose() {
        return BindingBuilder.bind(queueLimitClose()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_LIMIT_CLOSE);
    }
 
    /**
     * 爆仓
     *
     * @return
     */
    @Bean
    public Binding bindingCoinout() {
        return BindingBuilder.bind(queueCoinout()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_COINOUT);
    }
 
 
    /**
     * 价格操作
     *
     * @return
     */
    @Bean
    public Binding bindingPriceoperate() {
        return BindingBuilder.bind(queuePriceoperate()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_PRICEOPERATE);
    }
 
    /**
     * 平仓绑定
     *
     * @return
     */
    @Bean
    public Binding bindingCloseTrade() {
        return BindingBuilder.bind(queueCloseTrade()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_CLOSETRADE);
    }
 
    /**
     * 全仓爆仓绑定
     *
     * @return
     */
    @Bean
    public Binding bindingWholeBomb() {
        return BindingBuilder.bind(queueWholeBomb()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_WHOLE_BOMB);
    }
 
}