Skip to content

Instantly share code, notes, and snippets.

@kevinchugh
Created August 18, 2017 14:45
Show Gist options
  • Save kevinchugh/13f8187d24551daf719d90dc728c368c to your computer and use it in GitHub Desktop.
Save kevinchugh/13f8187d24551daf719d90dc728c368c to your computer and use it in GitHub Desktop.
prefix and post fix debatcher
// prefix
@Override
public void onSubscriptionData(BotContext ctx, RtmSubscriptionData messages)
{
JsonArray msgJsonArray = messages.getMessages();
JsonArray msgs = msgJsonArray.get(0).getAsJsonArray();
for (JsonElement msg : msgs)
{
try
{
ctx.getRtmProxy().publish(outputChannel, msg, Ack.YES);
logger.info("Published message: '{}'", msg);
}
catch (InterruptedException e)
{
logger.error("Execution interrupted", e);
Thread.currentThread().interrupt();
}
catch (RtmException e)
{
logger.error("RTM problem: ", e);
}
}
}
//postfix
@Override
public void onSubscriptionData(BotContext ctx, RtmSubscriptionData messages)
{
for (JsonElement msg : messages.getMessages())
{
try
{
JsonArray msgJsonArray = messages.getMessages();
JsonArray msgs = msgJsonArray.get(0).getAsJsonArray();
for (int i = 1; i < msgJsonArray.size(); i++)
{
msgs.addAll(msgJsonArray.get(i).getAsJsonArray());
}
for (int m = 0; m < msgs.size(); m++)
{
ctx.getRtmProxy().publish(outputChannel, msgs.get(m), Ack.YES);
logger.info("Published message: '{}'", msgs.get(m));
}
}
catch (InterruptedException e)
{
logger.error("Execution interrupted", e);
Thread.currentThread().interrupt();
}
catch (RtmException e)
{
logger.error("RTM problem: ", e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment