Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Salesforce emp Connector not waiting for event after subscribe in AWS Lambda #57

Open
gorugontula opened this issue Mar 12, 2019 · 1 comment

Comments

@gorugontula
Copy link

gorugontula commented Mar 12, 2019

I have a simple client using salesforce EMP connector and subscribing to a platform event. When I have it run from commandline on windows machine it works fine and subscription and subsequent events work fine. When I deploy the same code as a Java Lambda function in AWS - it successfully subscribes but does not wait/listen for events. Is there some limitation around using java Bayeaux client in AWS Lambda ?

Below is the code in Lambda handler -

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";
        }
    }
@PCI-API
Copy link

PCI-API commented Sep 30, 2021

Hello,

I am running into the same issue now with my instance of EMP connector. It will work locally, but when thrown into a lambda function, it will exit as soon as it subscribes. Did you ever come to a solution as to why the code doesn't wait/listen for events? I tried making the return type void or adding a sleep at the end of the handler, but that didn't seem to work.

Any help would be great here - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant