Created
August 18, 2017 14:45
-
-
Save kevinchugh/13f8187d24551daf719d90dc728c368c to your computer and use it in GitHub Desktop.
prefix and post fix debatcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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