我有一个使用Salesforce EMP连接器并订阅平台事件的简单客户端。当我在Windows计算机上从命令行运行它时,它可以正常工作,并且订阅和后续事件也可以正常工作。 当我在AWS中部署与Java Lambda函数相同的代码时-它成功预订但不等待/监听事件。在AWS Lambda中使用Java Bayeaux客户端有一些限制吗?
下面是Lambda处理程序中的代码-
public String handleRequest(Object input, Context context) {
try {
context.getLogger().log("Input: " + input);
Consumer<Map<String, Object>> consumer = event -> System.out.println(String.format("Received:\n%s", JSON.toString(event)));
BearerTokenProvider tokenProvider = new BearerTokenProvider(() -> {
try {
return LoginHelper.login(new URL(SFDC_TEST_URL), SFDC_TEST_USERNAME, SFDC_PASS_SEC_KEY);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
BayeuxParameters params = tokenProvider.login();
EmpConnector connector = new EmpConnector(params);
LoggingListener loggingListener = new LoggingListener(true, true);
connector.addListener(META_HANDSHAKE, loggingListener)
.addListener(META_CONNECT, loggingListener)
.addListener(META_DISCONNECT, loggingListener)
.addListener(META_SUBSCRIBE, loggingListener)
.addListener(META_UNSUBSCRIBE, loggingListener);
connector.setBearerTokenProvider(tokenProvider);
connector.setBearerTokenProvider(tokenProvider);
connector.start().get(5, TimeUnit.SECONDS);
TopicSubscription subscription = connector.subscribe(SFDC_TOPIC_EVENT_NAME, EmpConnector.REPLAY_FROM_TIP, consumer).get(2, TimeUnit.SECONDS);
System.out.println(String.format("Subscribed: %s", subscription));
// TODO: implement your handler
return "Hello from Lambda!";
}catch(Exception e) {
e.printStackTrace();
return "exited with error";
}
}