@@ -87,6 +87,11 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
87
87
*/
88
88
private String producerGroup ;
89
89
90
+ /**
91
+ * Topics that need to be initialized for transaction producer
92
+ */
93
+ private List <String > topics ;
94
+
90
95
/**
91
96
* Just for testing or demo program
92
97
*/
@@ -235,6 +240,22 @@ public DefaultMQProducer(final String namespace, final String producerGroup, RPC
235
240
produceAccumulator = MQClientManager .getInstance ().getOrCreateProduceAccumulator (this );
236
241
}
237
242
243
+ /**
244
+ * Constructor specifying namespace, producer group, topics and RPC hook.
245
+ *
246
+ * @param namespace Namespace for this MQ Producer instance.
247
+ * @param producerGroup Producer group, see the name-sake field.
248
+ * @param topics Topic that needs to be initialized for routing
249
+ * @param rpcHook RPC hook to execute per each remoting command execution.
250
+ */
251
+ public DefaultMQProducer (final String namespace , final String producerGroup , final List <String > topics , RPCHook rpcHook ) {
252
+ this .namespace = namespace ;
253
+ this .producerGroup = producerGroup ;
254
+ this .topics = topics ;
255
+ defaultMQProducerImpl = new DefaultMQProducerImpl (this , rpcHook );
256
+ produceAccumulator = MQClientManager .getInstance ().getOrCreateProduceAccumulator (this );
257
+ }
258
+
238
259
/**
239
260
* Constructor specifying producer group and enabled msg trace flag.
240
261
*
@@ -290,6 +311,41 @@ public DefaultMQProducer(final String namespace, final String producerGroup, RPC
290
311
}
291
312
}
292
313
314
+ /**
315
+ * Constructor specifying namespace, producer group, topics, RPC hook, enabled msgTrace flag and customized trace topic
316
+ * name.
317
+ *
318
+ * @param namespace Namespace for this MQ Producer instance.
319
+ * @param producerGroup Producer group, see the name-sake field.
320
+ * @param topics Topic that needs to be initialized for routing
321
+ * @param rpcHook RPC hook to execute per each remoting command execution.
322
+ * @param enableMsgTrace Switch flag instance for message trace.
323
+ * @param customizedTraceTopic The name value of message trace topic.If you don't config,you can use the default
324
+ * trace topic name.
325
+ */
326
+ public DefaultMQProducer (final String namespace , final String producerGroup , final List <String > topics ,
327
+ RPCHook rpcHook , boolean enableMsgTrace , final String customizedTraceTopic ) {
328
+ this .namespace = namespace ;
329
+ this .producerGroup = producerGroup ;
330
+ this .topics = topics ;
331
+ defaultMQProducerImpl = new DefaultMQProducerImpl (this , rpcHook );
332
+ produceAccumulator = MQClientManager .getInstance ().getOrCreateProduceAccumulator (this );
333
+ //if client open the message trace feature
334
+ if (enableMsgTrace ) {
335
+ try {
336
+ AsyncTraceDispatcher dispatcher = new AsyncTraceDispatcher (producerGroup , TraceDispatcher .Type .PRODUCE , customizedTraceTopic , rpcHook );
337
+ dispatcher .setHostProducer (this .defaultMQProducerImpl );
338
+ traceDispatcher = dispatcher ;
339
+ this .defaultMQProducerImpl .registerSendMessageHook (
340
+ new SendMessageTraceHookImpl (traceDispatcher ));
341
+ this .defaultMQProducerImpl .registerEndTransactionHook (
342
+ new EndTransactionTraceHookImpl (traceDispatcher ));
343
+ } catch (Throwable e ) {
344
+ logger .error ("system mqtrace hook init failed ,maybe can't send msg trace data" );
345
+ }
346
+ }
347
+ }
348
+
293
349
@ Override
294
350
public void setUseTLS (boolean useTLS ) {
295
351
super .setUseTLS (useTLS );
@@ -1316,4 +1372,11 @@ public void setBackPressureForAsyncSendSize(int backPressureForAsyncSendSize) {
1316
1372
defaultMQProducerImpl .setSemaphoreAsyncSendSize (backPressureForAsyncSendSize );
1317
1373
}
1318
1374
1375
+ public List <String > getTopics () {
1376
+ return topics ;
1377
+ }
1378
+
1379
+ public void setTopics (List <String > topics ) {
1380
+ this .topics = topics ;
1381
+ }
1319
1382
}
0 commit comments