Azure Service Bus SQLFilter无法使用Azure Java SDK正常工作

时间:2019-05-10 14:18:18

标签: java azure azure-servicebus-queues azure-java-sdk

我正在尝试仅检索满足过滤器中指定条件但不起作用的消息。它只是返回所有消息。我可以看到该规则已在资源管理器中应用,但邮件未得到过滤。

下面是我的代码段

public class MyServiceBusTopicSubscriber {
  static final Gson GSON = new Gson();

  public static void main(String[] args) throws Exception, ServiceBusException {
    String connectionString = "MyConnectionString";
    SubscriptionClient subscription1Client = new SubscriptionClient(new ConnectionStringBuilder(connectionString, "myTopic"), ReceiveMode.PEEKLOCK);
    // Drop existing rules and add a TrueFilter
    for (RuleDescription rd : subscription1Client.getRulesAsync().get()) {
        subscription1Client.removeRuleAsync(rd.getName());
    }
    RuleDescription ruleDescription = new RuleDescription("FilterEvents");
    ruleDescription.setFilter( new SqlFilter("1!=1"));
    SqlRuleAction action = new SqlRuleAction("set FilterTag = 'true'");
    ruleDescription.setAction(action);
    subscription1Client.addRuleAsync(ruleDescription);
    registerMessageHandlerOnClient(subscription1Client);
}

static void registerMessageHandlerOnClient(SubscriptionClient receiveClient) throws Exception {

    ISessionHandler sessionHandler = new ISessionHandler() {
        @Override
        public CompletableFuture<Void> onMessageAsync(IMessageSession iMessageSession, IMessage message) {
            System.out.println(ToStringBuilder.reflectionToString(message));
            byte[] body = message.getBody();
            String data = new String(Base64.decodeBase64(body), UTF_8);
            Response response = GSON.fromJson(data, Response.class);
            System.err.println(GSON.toJson(response));

            return receiveClient.completeAsync(message.getLockToken());
        }

        @Override
        public CompletableFuture<Void> OnCloseSessionAsync(IMessageSession iMessageSession) {
            return null;
        }

        @Override
        public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {

        }
    };
    receiveClient.registerSessionHandler(sessionHandler);
}

}

在库中,它写为

/**
 * Represents a filter expression that is evaluated against a message on a 
topic. This client library provides support for creating only limited types of filters.
* This is an empty interface to serve as root interface for all supported filter types.
*
* @since 1.0
*/
public abstract class Filter {
 // No methods. Just a skeleton root class for filters
 // Filter execution happens in the cloud on .net runtime. There is no point implementing custom filters in Java.
}

它不支持Java吗?还是我做错了什么?指针会有所帮助

0 个答案:

没有答案