{"id":4779,"date":"2022-12-19T21:39:27","date_gmt":"2022-12-19T21:39:27","guid":{"rendered":"https:\/\/dalelane.co.uk\/blog\/?p=4779"},"modified":"2022-12-19T21:44:39","modified_gmt":"2022-12-19T21:44:39","slug":"xbox-live-events-for-kafka","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=4779","title":{"rendered":"Xbox LIVE events for Kafka"},"content":{"rendered":"<p><strong>I&#8217;ve made a <a href=\"https:\/\/github.com\/dalelane\/kafka-connect-xboxlive-source\">Kafka Connect source connector<\/a> for sending &#8220;real-time&#8221; events from Xbox LIVE to Kafka topics.<\/strong><\/p>\n<p><em>Quick primer if you&#8217;re not a gamer or don&#8217;t know what I&#8217;m talking about!<br \/>\nThe Xbox platform comes with a social aspect: details about games you play and the achievements you earn playing them, are shared with your friends on the Xbox LIVE service. That is the source of data I&#8217;m using here.<\/em><\/p>\n<p>Create an API key for your Xbox LIVE account, and <a href=\"https:\/\/kafka.apache.org\/documentation\/#connect_user\">run the Connector<\/a> with it, and it will start producing two streams of events to your Kafka cluster:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.dropbox.com\/s\/kllcgu53ljkmnis\/topics.png?raw=1\" style=\"border: thin black solid\"\/><br \/>\n<small>Screenshot from <a href=\"https:\/\/ibm.github.io\/event-streams\/\">Event Streams<\/a>, but as a Kafka Connect connector, you could use any flavour of Kafka, including Apache Kafka.<\/small><\/p>\n<div style=\"margin-top: 20px;\"><code style=\"background-color: #ffffc0; font-weight: 600; color: #770000;\">ACHIEVEMENTS<\/code><br \/>\nEvents when one of your friends earns an achievement.<\/div>\n<p><code style=\"background-color: #ffffc0; font-weight: 600; color: #770000;\">PRESENCE<\/code><br \/>\nEvents when your friends start playing a game, or go online\/offline.<\/p>\n<p>Details about the attributes of each of these events can be found in the <a href=\"https:\/\/github.com\/dalelane\/kafka-connect-xboxlive-source#kafka-connect-xboxlive-source\">Connector README<\/a>, but here are a few screenshots to give you an idea.<\/p>\n<p>An example message on the <code><strong>ACHIEVEMENTS<\/strong><\/code> topic.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.dropbox.com\/s\/vzozvlqrasa5uv1\/achievement-1.png?raw=1\" style=\"border: thin black solid\"\/><\/p>\n<p><!--more-->Events look like this:<\/p>\n<pre style=\"max-height: 250px; max-width: 90%; padding: 10px; overflow: scroll; overflow-x: scroll; border: thin black solid; font-size: smaller; background-color: #eeeeee; color: black; margin-left: 16px;\">{\n    \"date\": \"2022-11-30T22:13:31.78Z\",\n    \"gamertag\": \"nicthemighty\",\n    \"gamername\": \"Nic Townsend\",\n    \"name\": \"Beyond The Horizon\",\n    \"description\": \"Completed 'Radio Silence.'\",\n    \"icon\": \"http:\/\/images-eds.xboxlive.com\/image?url=27S1DHqE.cHkmFg4nspsd6NoGj7jZQMki04gpiRpEPuwG3HCQIFJuvdOFdGo12yCzLSqj44HuZfLxpyO5k2.SV6ALPJOEvOsHra7GYt_BP0JRVg_FGOI2vo8IozeWvtHGXU01cfVQ0CXtbgDmatXRg--\",\n    \"contentname\": \"DEATHLOOP\",\n    \"contentimage\": \"http:\/\/store-images.s-microsoft.com\/image\/apps.5858.14634955238674857.649b7ff9-0dfc-4951-9b65-c5d815215da6.90208516-ba3b-47a9-a130-ef94cf860f5b\",\n    \"platform\": \"XboxOne\",\n    \"gamerscore\": 30,\n    \"rarityscore\": 5,\n    \"raritycategory\": \"Rare\"\n  }<\/pre>\n<p>Notice that the Connector lets you specify a prefix to add to the topic names that it uses, which is how you can produce events to a topic like <code>XBOX.LIVE.ACHIEVEMENTS<\/code> like I am here.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.dropbox.com\/s\/at8039aevyxjmji\/achievement-2.png?raw=1\" style=\"border: thin black solid\"\/><\/p>\n<p>Events on the <code><strong>PRESENCE<\/strong><\/code> topic will identify when a gamer goes online or offline. If the user is playing a game, the event will include the details of the game that they are playing.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.dropbox.com\/s\/hjk7cqa7ouyrwib\/presence.png?raw=1\" style=\"border: thin black solid\"\/><\/p>\n<p>Events look like this:<\/p>\n<pre style=\"max-height: 250px; max-width: 90%; padding: 10px; overflow: scroll; overflow-x: scroll; border: thin black solid; font-size: smaller; background-color: #eeeeee; color: black; margin-left: 16px;\">{\n    \"date\": \"2022-12-19T01:52:03.961465802Z\",\n    \"userid\": \"2533274819921149\",\n    \"state\": \"Online\",\n    \"titleid\": \"2001700854\",\n    \"titlename\": \"Call of Duty\u00ae: Modern Warfare\u00ae II\"\n}<\/pre>\n<p><strong>How does it work?<\/strong><\/p>\n<p>The Connector is just a quick-and-simple wrapper around the REST API from <a href=\"https:\/\/xbl.io\/\">OpenXBL<\/a> who provide an unofficial API for getting data from Xbox LIVE. It polls the APIs that they provide, and when it sees something new, emits that as a Kafka event.<\/p>\n<p>The poll interval is configurable, but you can set it to poll every fifty seconds and still keep under the rate limit for a free tier API key.<\/p>\n<p><strong>Why did I make it?<\/strong><\/p>\n<p>I need a real-but-fun live source of events for a simple stream processing demo. I figured I might be able to do something fun with this.<\/p>\n<p>For example, I can show enriching events, such as by making a stream processor that takes the <code>PRESENCE<\/code> events and looks up user details for the user id in the event.<\/p>\n<p>And I can show examples of more stateful stream processing, such as emitting events when more than a few people are playing the same game at the same time, or emitting events when someone has been playing a game for longer than an hour.<\/p>\n<p>I could&#8217;ve done this with a fake synthetic data source, but I thought it might be more interesting to do it with something real.<\/p>\n<p><strong>Want to use it?<\/strong><\/p>\n<p>This is just a quick hack for my own use, but I thought I&#8217;d share it. If you need (nearly) real-time Xbox events in kafka, you can find the Connector on <a href=\"https:\/\/github.com\/dalelane\/kafka-connect-xboxlive-source#kafka-connect-xboxlive-source\">github<\/a>.<\/p>\n<p>I&#8217;ve included <a href=\"https:\/\/github.com\/dalelane\/kafka-connect-xboxlive-source\/blob\/master\/README.md\">documentation for the config parameters<\/a>, and <a href=\"https:\/\/github.com\/dalelane\/kafka-connect-xboxlive-source\/blob\/master\/sample-connector.properties\">sample config parameters<\/a>, in the repo as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve made a Kafka Connect source connector for sending &#8220;real-time&#8221; events from Xbox LIVE to Kafka topics. Quick primer if you&#8217;re not a gamer or don&#8217;t know what I&#8217;m talking about! The Xbox platform comes with a social aspect: details about games you play and the achievements you earn playing them, are shared with your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4798,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[593,584,191,192],"class_list":["post-4779","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code","tag-apachekafka","tag-kafka","tag-xbox","tag-xbox-live"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4779"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4779\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/media\/4798"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}