0

I have segment working and sending events to MixPanel using javascript. Now we want to do it using Java. I tried to follow the example on https://segment.com/docs/sources/server/java/#selecting-integrations Copying from the link above, I added, similarly, to my code, the snippets:

Analytics analytics = Analytics.builder(writeKey).build();
analytics.enqueue(IdentifyMessage.builder()
    .userId("f4ca124298")
    .traits(ImmutableMap.builder()
        .put("name", "Michael Bolton")
        .put("email", "mbolton@initech.com")
        .build()
    )
);
analytics.enqueue(TrackMessage.builder("Item Purchased")
    .userId("f4ca124298")
    .properties(ImmutableMap.builder()
        .put("revenue", 39.95)
        .put("shipping", "2-day")
        .build()
    )
);
analytics.flush()

The program is running correctly, but I cannot see any event on MixPanel. I am wondering what I might be doing wrong.

Is anyone able to assist?

Thank you in advance,

Thais.

ThaisK
  • 365
  • 1
  • 4
  • 22

1 Answers1

-1

Are you trying to run it from a standalone java client? I faced similar issue when I was running from JUnit, however when I add a delay of a few seconds, it works.

So I am assuming segments is asynchronously posting messages to its server, when JVM shuts down before the message has been posted, we do not see any message but adding a delay works. Hope that helps.

Nitish
  • 1
  • 1