Mobile Development
MVVM with Xamarin Classic: The Basics Pascal Naber 03 Mar, 2015
<providers>
<schedule-provider name="schedule">
<cron-schedule scheduleid="cron-trigger" cronExpression="0 0 * * * ?" />
</schedule-provider>
</providers>
This cron-trigger can be used in a schedule-listener to invoke a certain action or chain of actions which is explained in the next step. The cron-expression above will be fired every hour. Step 2) Create a listener that creates an ESB aware message Each time the above trigger is fired, a listener should be triggered that can catch the event and process it. In this example the event processor will create a new ESB aware message and put the hashtag in it to look for. xml-configuration <listeners>
<scheduled-listener name="cron-schedule-listener"
scheduleidref="cron-trigger"
event-processor="org.xebia.soa.esb.twitter.TwitterConfigurationReader" />
</listeners>
event-processor public Message composeMessage() throws SchedulingException {
// TODO This should be read from a configuration file or database.
Message message = MessageFactory.getInstance().getMessage();
message.getBody().add("Xebia");
return message;
}
In this case we put "Xebia" as the hashtag to look for. If you want you can configure some property file for example that contains all the hashtags to look for. Step 3) Create an action that searches for the tweets and reposts them if needed Next step is to create a service that contains an action that will search for all tweets containing the string that was put in the message body in step 2 and retweets those messages if they are new. xml-configuration <services>
<service category="ServiceSocialMedia" name="TwitterService" description="Fetching Twitter Messages">
<listeners>
<scheduled-listener name="cron-schedule-listener"
scheduleidref="cron-trigger"
event-processor="org.xebia.soa.esb.twitter.TwitterConfigurationReader" />
</listeners>
<actions>
<action name="action" class="org.xebia.soa.esb.twitter.ConverterAction" />
</actions>
</service>
</services>
action Twitter twitter = new TwitterFactory(configurationBuilder.build()).getInstance();
// Query latest tweets of current user
Query queryTweeted = new Query("from:" + USER_NAME);
QueryResult tweeted = twitter.search(queryTweeted);
// Execute search based on hashtag provided in message
String qrySearch = "#" + message.getBody().get();
Query query = new Query(qrySearch);
query.setSinceId(tweeted.getMaxId());
QueryResult result = twitter.search(query);
// Add number of results to ESB message for further processing
message.getBody().add("tweets", result.getTweets().size());
for (Tweet tweet : result.getTweets()) {
// retweet it
twitter.retweetStatus(tweet.getId());
}
return message;
For the configurationBuilder you will have to create the OAuth Access token yourself, by registering your application on the twitter website.
First we query for the last tweeted message by the current user. The id of that tweet will be used in the next query to fetch only those tweets with a higher id.
For each tweet found, we retweet that by passing the original id. Notice that we only send the id, and not the whole message. Step 4) Deploy and have fun You can use maven to create a jar file out of it and deploy this to the JBoss AS. Once deployed this application will start retweeting all tweets containing #Xebia to your own twitter account. Conclusion Typical ESB provider these days support connectors for webservices, file systems, JMS, ftp, ... The next step would be to create connectors with social media like Twitter, Facebook, ...
Although you can do almost everything with JBoss ESB what you want, a big improvement would be to have a more user friendly designer tool. Currently you quickly have to fall back on hard coding xml files, which can be difficult. It would be nice to be able to rewrite this whole blog post, by using for example only drag and drop components ;-) Possible extensions: Of course you can add additional actions that analyze the contents of the messages.