Skip to content

Commit

Permalink
Merge pull request #202 from yg3630536/feature/optimization-monitor-t…
Browse files Browse the repository at this point in the history
…opic

* specific topic
  • Loading branch information
junqizhang-dev committed May 20, 2020
2 parents 257f73d + 30547f9 commit 69e0be2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/webank/weid/config/FiscoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class FiscoConfig {

private static final Logger logger = LoggerFactory.getLogger(FiscoConfig.class);
private static final Validator validator = new Validator();
// 配置topic
public static String topic;

// Note that all keys are appended with a colon ":" to support regex auto-loading

@NotNull(message = "the bcos.version is undefined")
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/webank/weid/service/fisco/WeServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package com.webank.weid.service.fisco;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -177,7 +179,22 @@ protected int getTimeOut(int timeOut) {
return timeOut;
}
}


/**
* 获取AMOP监听的topic.
*
* @return 返回topic集合,目前sdk只支持单topic监听
*/
protected Set<String> getTopic() {
Set<String> topics = new HashSet<String>();
if (StringUtils.isNotBlank(FiscoConfig.topic)) {
topics.add(fiscoConfig.getCurrentOrgId() + "_" + FiscoConfig.topic);
} else {
topics.add(fiscoConfig.getCurrentOrgId());
}
return topics;
}

/**
* 获取Web3j对象.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ protected void initWeb3j() {
service = buildFiscoBcosService(fiscoConfig);
service.setPushCallback((ChannelPushCallback) pushCallBack);
// Set topics for AMOP
List<String> topics = new ArrayList<String>();
topics.add(fiscoConfig.getCurrentOrgId());
service.setTopics(topics);

service.setTopics(new ArrayList<>(super.getTopic()));
try {
service.run();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.fisco.bcos.channel.client.ChannelPushCallback;
Expand Down Expand Up @@ -107,9 +105,7 @@ protected void initWeb3j() {
service = buildFiscoBcosService(fiscoConfig);
service.setPushCallback((ChannelPushCallback) pushCallBack);
// Set topics for AMOP
Set<String> topics = new HashSet<String>();
topics.add(fiscoConfig.getCurrentOrgId());
service.setTopics(topics);
service.setTopics(super.getTopic());
try {
service.run();
} catch (Exception e) {
Expand Down

0 comments on commit 69e0be2

Please sign in to comment.