Drools Complex Event Processing with Twitter4J. Toshiya Kobayashi Red Hat Senior Software Maintenance Engineer



Similar documents
Real World Hadoop Use Cases

Open Source Business Rules Management System Enables Active Decisions

Introduction to Programming Tools. Anjana & Shankar September,2010

Drools: The Business Logic Integration Platform

Getting Started Android + Linux. February 27 th, 2014

A Rules Engine Experiment: Lessons Learned on When and How to use a Rules-Based Solution

Production time profiling On-Demand with Java Flight Recorder

Configuration Manual Yahoo Cloud System Benchmark (YCSB) 24-Mar-14 SEECS-NUST Faria Mehak

Open source business rules management system

Scheduling. Reusing a Good Engine. Marian Edu. medu@ganimede.ro

Frysk The Systems Monitoring and Debugging Tool. Andrew Cagney

Developing tests for the KVM autotest framework

How To Use Guvnor On Linux (Web) (Webapp) (Dnu) (Gpl) (Netware) (Demo) (Powerpoint) (Orgode) (Proper) (Programming) (Server

Welcome The webinar will begin shortly

JSR-303 Bean Validation

Cloud Powered Mobile Apps with Azure

Simplifying the Development of Rules Using Domain Specific Languages in DROOLS

Practical Android Projects Lucas Jordan Pieter Greyling

How to Participate in a Twitter Pitch Party

Rapid Application Development. and Application Generation Tools. Walter Knesel

Sophos Mobile Control Web service guide

Using Files as Input/Output in Java 5.0 Applications

OpenDaylight & PacketFence install guide. for PacketFence version 4.5.0

Big Data : Experiments with Apache Hadoop and JBoss Community projects

Enterprise Service Bus

Service Integration course. Cassandra

Turnitin User Guide. Includes GradeMark Integration. January 2014 (revised)

Memopol Documentation

RN-131-PICTAIL & RN-171-PICTAIL Evaluation Boards

Automatic Pull Request Integration

GitLab as an Alternative Development Platform for Github.com

Capabilities of a Java Test Execution Framework by Erick Griffin

AVRO - SERIALIZATION

MOOSE-Based Application Development on GitLab

! E6893 Big Data Analytics:! Demo Session II: Mahout working with Eclipse and Maven for Collaborative Filtering

Collecting and archiving tweets: a DataPool case study

NotePad No More: - A Personal Survey of HTML5 Developer Toolsets. Stewart Christie - Tizen and HTML5 Community Manager.

Introduction to Oracle Mobile Application Framework Raghu Srinivasan, Director Development Mobile and Cloud Development Tools Oracle

LoadRunner and Performance Center v11.52 Technical Awareness Webinar Training

OpenShift on you own cloud. Troy Dawson OpenShift Engineer, Red Hat November 1, 2013

Continuous Integration on System z

Evaluation and implementation of CEP mechanisms to act upon infrastructure metrics monitored by Ganglia

Programming Autodesk PLM 360 Using REST. Doug Redmond Software Engineer, Autodesk

HBase Key Design coreservlets.com and Dima May coreservlets.com and Dima May

Developing Android Apps with the ArcGIS Runtime SDK for Android. Dan

Java Forum Nord Dirk Mahler

OpenShift is FanPaaStic For Java EE. By Shekhar Gulati Promo Code JUDCON.IN

CS506 Web Design and Development Solved Online Quiz No. 01

Oracle Application Development Framework Overview

SETTING UP YOUR JAVA DEVELOPER ENVIRONMENT

Drools at Intermountain Healthcare. Herman Post Homer Warner Center 5/9/2011

Platform as a Service and Container Clouds

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Google Cloud Print Administrator Configuration Guide

Copyright 2014 Jaspersoft Corporation. All rights reserved. Printed in the U.S.A. Jaspersoft, the Jaspersoft

Instrumentation for Linux Event Log Analysis

Ikasan ESB Reference Architecture Review

Robotium Automated Testing for Android

JBOSS ESB. open source community experience distilled. Beginner's Guide. Enterprise. Magesh Kumar B

The Monitis Monitoring Agent ver. 1.2

Integration of an open source rule engine to enhance the IHTSDO Workbench testing

Towards Smart and Intelligent SDN Controller

iway iway Business Activity Monitor User's Guide Version Service Manager (SM) DN

Gentran Integration Suite. Archiving and Purging. Version 4.2

Running a Program on an AVD

Drools Developer's Cookbook

Paul Barham Program Manager - Java. David Staheli (dastahel@microsoft.com) Software Development Manager - Java

Database Studio is the new tool to administrate SAP MaxDB database instances as of version 7.5.

WebSphere MQ Managed File Transfer. Parineeta Mattur

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Using Git for Project Management with µvision

C Programming Review & Productivity Tools

Security Analytics Topology

Koen Aers JBoss, a division of Red Hat jbpm GPD Lead

Android Security Evaluation Framework

The power of root on Android emulators

MSDG Services Integration Document Draft Ver 1.2

Automated performance testing using Maven & JMeter. George Barnett, Atlassian Software

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Working Copy 1.4 users manual

CI/CD Cheatsheet. Lars Fabian Tuchel Date: 18.March 2014 DOC:

... Introduction... 17

Enterprise Informatization LECTURE

Grid-In-Hand Mobile Grid Revised 1/27/15

Technical Data Sheet: imc SEARCH 3.1. Topology

ApacheCon Infinite Session Clustering with Apache Shiro & Cassandra

Facebook: Cassandra. Smruti R. Sarangi. Department of Computer Science Indian Institute of Technology New Delhi, India. Overview Design Evaluation

Advanced Java Client API

Project Report BIG-DATA CONTENT RETRIEVAL, STORAGE AND ANALYSIS FOUNDATIONS OF DATA-INTENSIVE COMPUTING. Masters in Computer Science

AAI for Mobile Apps How mobile Apps can use SAML Authentication and Attributes. Lukas Hämmerle

Transcription:

Drools Complex Event Processing with Twitter4J Toshiya Kobayashi Red Hat Senior Software Maintenance Engineer

Agenda Overview Simple Demo Guvnor Integration Developing a bot

Agenda Overview Simple Demo Guvnor Integration Developing a bot Wifi SSID : Judcon2012-6 pass : 6judcon2012

Overview Knowlege Base with STREAM mode Twitter Stream API Rule1 Rule2 Rule3 Tweet Tweet Match? Fire! Tweet EntryPoint twitter Knowlege Session Tweet

Simple Demo Command Line Interface with Eclipse Static rules Good for understanding the basic concept DRL Tweet Standalone Java

Simple Demo https://github.com/droolsjbpm/droolsjbpm -contributed-experiments original contains this 'Simple Demo' only https://github.com/tkobayas/droolsjbpmcontributed-experiments fork judcon branch contains 'Guvnor integration' and 'Bot' as well

Simple Demo $ git clone git://github.com/tkobayas/droolsjbpmcontributed-experiments.git $ cd droolsjbpm-contributed-experiments $ git checkout track origin/judcon $ cd twittercbr/ $ mvn clean package

Drools Complex Event Processing http://www.jboss.org/drools/droolsfusion.html Known as Drools Fusion "Complex Event Processing, or CEP, is primarily an event processing concept that deals with the task of processing multiple events with the goal of identifying the meaningful events within the event cloud. CEP employs techniques such as detection of complex patterns of many events, event correlation and abstraction, event hierarchies, and relationships between events such as causality, membership, and timing, and event-driven processes."

Drools CEP Declare Event in Rule declare Status @role( event ) @timestamp( createdat ) @expires( 2s ) end rule "Dump tweets" when $s : Status() from entry-point "twitter" then System.out.println(... ); end

Drools CEP Declare Event in Rule declare Status @role( event ) @timestamp( createdat ) @expires( 2s ) end rule "Dump tweets" when $s : Status() from entry-point "twitter" then System.out.println(... ); end

Drools CEP Declare Event in Rule declare Status @role( event ) @timestamp( createdat ) @expires( 2s ) end rule "Dump tweets" when $s : Status() from entry-point "twitter" then System.out.println(... ); end

Drools CEP Declare Event in Rule declare Status @role( event ) @timestamp( createdat ) @expires( 2s ) end rule "Dump tweets" when $s : Status() from entry-point "twitter" then System.out.println(... ); end

Drools CEP Declare Event in Rule declare Status @role( event ) @timestamp( createdat ) @expires( 2s ) end rule "Dump tweets" when $s : Status() from entry-point "twitter" then System.out.println(... ); end

Drools CEP Temporal operators rule "Dump tweets from user conversation" when $s1 : Status( $name : user.screenname ) from entry-point "twitter" $s2 : Status( inreplytoscreenname == $name, this after[1ms,2m] $s1 ) from entry-point "twitter" then System.out.println(... ); 1ms 2min end $s1 this

Drools CEP Set STREAM mode KnowledgeBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); conf.setoption( EventProcessingOption.STREAM ); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( conf );

Drools CEP Create an Entry Point and insert events into it in a different thread final WorkingMemoryEntryPoint ep = ksession.getworkingmemoryentrypoint( "twitter" );... public void onstatus( Status status ) { ep.insert( status ); }

Fire until halt Drools CEP ksession.fireuntilhalt();

Twitter4J http://twitter4j.org Java library for the Twitter API REST Search Stream

Twitter4J Stream API Streamed Tweets sample filter firehose links retweet User Stream Site Stream

Twitter4J Register to https://dev.twitter.com/ to acquire your access token

Twitter4J Edit twitter4j.properties to enable OAuth oauth.consumerkey=xxxxxxxxxxxxxx oauth.consumersecret=xxxxxxxxxxxxxxxx oauth.accesstoken=xxxxxxxxxxxxxxxx oauth.accesstokensecret=xxxxxxxxxxxxxx

Twitter4J Get a TwitterStream instance, add a custom listener and read a sample stream StatusListener listener = new TwitterStatusListener( ep ); TwitterStream twitterstream = new TwitterStreamFactory().getInstance(); TwitterStream.addListener( listener ); twitterstream.sample();

Twitter4J A custom listener public class TwitterStatusListener implements StatusListener {... public void onstatus( Status status ) { ep.insert( status ); }...

Twitter4J Offline stream is useful in case that Twitter/network is unavailable Later Tweet Persist as a file Tweet emulate stream Tweet dump file

Twitter4J Offline stream is useful in case that Twitter/network is unavailable private static void feedevents( final StatefulKnowledgeSession ksession, final WorkingMemoryEntryPoint ep ) { try { StatusListener listener = new TwitterStatusListener( ep ); ObjectInputStream in = new ObjectInputStream( new FileInputStream( "src/main/resources/twitterstream.dump" ) ); SessionPseudoClock clock = ksession.getsessionclock(); for( int i = 0; ; i++ ) { try { Status st = (Status) in.readobject(); clock.advancetime( st.getcreatedat().gettime() - clock.getcurrenttime(), TimeUnit.MILLISECONDS ); listener.onstatus( st ); } catch( IOException ioe ) { break; }

DEMO Simple Demo Wifi SSID : Judcon2012-6 pass : 6judcon2012

Filter stream Twitter4J TwitterStream twitterstream = new TwitterStreamFactory().getInstance(); twitterstream.addlistener( listener ); FilterQuery query = new FilterQuery(); query.track(new String[]{"#judcon"}); twitterstream.filter(query);

Guvnor Integration Authoring rules with Guvnor GUI Editor Simple Web Application which re-loads results with Ajax poll Dynamic rule change DRL Tweet Guvnor JBoss AS Web Application JBoss AS

Guvnor http://www.jboss.org/drools/drools-guvnor.htm A centralized repository for Drools Knowledge Bases, with rich web based GUIs

Guvnor Develop rules with CEP support Note: There are some issues in Editor with CEP. Please check the latest build.

Guvnor https://github.com/droolsjbpm/guvnor/ original https://github.com/tkobayas/guvnor/ fork judcon branch contains quick fixes for some rule editor CEP issues. I will raise JIRAs soon ;) $ git clone git://github.com/tkobayas/guvnor.git $ cd guvnor $ git checkout track origin/judcon $ mvn clean package -DskipTests Note: There are some issues in Editor with CEP. Please check the latest build.

Knowledge Agent Knowledge Agent supports dynamic rule loading from Guvnor repository KnowledgeBaseConfiguration kbaseconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbaseconf.setoption(eventprocessingoption.stream); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConf); kagent = KnowledgeAgentFactory.newKnowledgeAgent("MyAgent", kbase); kagent.applychangeset(resourcefactory.newclasspathresource("changeset.xml")); Note: The KnowledgeBaseConfiguration will be re-used when the knowledge agent re-build a knowledge base. So Stream mode will be applied continuously

Knowledge Agent ResourceChangeScanner scans the repository with the configured interval ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration(); sconf.setproperty("drools.resource.scanner.interval", "20"); ResourceFactory.getResourceChangeScannerService().configure(s conf); ResourceFactory.getResourceChangeScannerService().start(); ResourceFactory.getResourceChangeNotifierService().start(); Note: Use the same Drools version in Guvnor and the client

Knowledge Agent...... Use KnowledgeAgentEventListener to trigger action on resource change kagent.addeventlistener(new HaltKnowledgeAgentEventListener()); static class HaltKnowledgeAgentEventListener extends DefaultKnowledgeAgentEventListener { public void afterchangesetapplied(afterchangesetappliedevent event) { // If the changeset is updated, halt the ksession and re-run if (ksessionrunning) { try { stopknowledgesession(); run(); } catch (Exception e) {...

DEMO Guvnor Integration

Developing a bot Have fun Do not spam DRL Tweet Guvnor JBoss AS Standalone Java Tweet

Developing a bot Please follow @scolding_bot https://twitter.com/#!/scolding_bot

Developing a bot Which stream (filter/user/sample) do you use? How much do you narrow down the stream by FilterQuery? How to deal with rule update What condition can be hard-coded? How to maintain the daemon thread Please follow @scolding_bot https://twitter.com/#!/scolding_bot

Developing a bot Too frequent login will be restricted Too frequent tweet will be restricted Duplicate tweet will be restricted Please follow @scolding_bot https://twitter.com/#!/scolding_bot

DEMO Developing a bot Please follow @scolding_bot https://twitter.com/#!/scolding_bot