 I asked me to give a bit of an opening talk. I'm going to make that full screen. A bit of an opening talk just to warm everyone up and to get everyone's brains flowing. Blood flowing through their brains rather. That is full screen. I'm going to be talking very quickly about a monorail. This is a really personal problem that I discovered. At Meducation we built this huge Rails app that tried to do absolutely everything. Dwy'n gwybod bod yn eu ch interestsu ym mlynedd, byddwch chi ddim yn gobeithiadau, a gynnydd i ysgolw'ch gwbl sydd gennymol a'r ddweudion. Dw i ysgolw'ch pan fyddwch chi'n gysylltio? Dwi'n meddwl'u gennaid cyd-dill yn 50 o 50 o ddweudion? Dwi ddim yn gweld gweithio'n meddwl. F ky店 ddim yn gromohon o'r Foddan, a mor hyn ar gyfer o gennymol. Dwi ddim yn gweithio'n meddwl yn ddweudion sydd hordi! Ydiogel Adeglai dw i'r cyflinau between all the different components. You get strings of behaviours, one of these sorts of two patterns, create a user, and then do this, and then do this, and then do this. Really bad programming. But things that just when you're trying to get everything into one space naturally happen. It gets really messy, it gets really complex, it becomes hard to understand, and that means it becomes hard to maintain, and that means bugs. So one of the solutions to this is PubSub, the published subscribe pattern. So this is something we did about a year ago, and we transferred this large monorail, broke it up into lots and lots of components, and got them all talking to each other. So if you don't know PubSub, this is what PubSub looks like. You have one or more publishers that send messages about events out into the ecosystem, and then you have lots of subscribers that are listening to those events. And the publishers don't know who they're publishing to, and the subscribers don't know where the messages are coming from, and don't know about each other. All they know is that something's happened, and they need to act on it. So to give you an example of what this might look like, you might have say a mobile app and a website, both of which are publishing a message out about a new user being created, and then you might have all of these different things that respond to that. So these are from our app, we have something that sends a welcome email, someone that generates some friendship suggestions, something that determines a user's clout that builds an initial news feed for them. And all of these things have totally their own concerns, which is great because it means you can make very, very specific services. You can get great loose coupling across this whole network, which gives you scalability, it makes it very easy to add and remove functionality, gives you a great speed of iteration. So we made a gem called Propono, which is what I'm going to be talking about, and you're all going to use in a minute, hopefully. And this is a gem that's built on top of Amazon Web Services, and which gives you PubSub in an incredibly simple fashion within Ruby. So we built this on top of simple notification services and simple queue services. You don't really need to worry about any of this, but I'll just show you very quickly how it works. You publish a message out onto an SNS topic that gets proxied onto various SQS queues, and that ends up with various subscribers that are listening for these messages. But Propono handles all of this automatically. It creates those things, it securely glues everything together. It handles failures, errors, retries, all of the different problems and all the different scenarios. There's no setup. It's instantly and in effect infinitely on Amazon's scalable. It's as reliable as you can get. It's really fast, and it's insanely cheap. We send millions of messages between all our different services each month, and it costs us a couple of euros. It's a two-function API. You have a subscriber that's listening to queues. It listens on a topic, and every time a message appears, it gets something, and it does something with it. And you have a publisher, and this publisher publishes messages back onto that topic. I want to try an example. So if you all open up your laptops, you guys are going to play and start publishing some messages into some code I'm about to try and write. And I mentioned this earlier to those of you that are here. Please use the conference internet responsibly. I'm sure I'm not the only speaker that's going to be asking you guys to do stuff and interact with me. If you have any of these things running, it will probably kill it for everyone. There's 550 people here all on the same internet connection. So please do turn those things off if you have any of them running. If you crack open a terminal, and run gem install proponent, I'll give you a second to do that. I'll put that back up in a second. One I'm going to work out for the next few minutes is who's here. And I've got three objectives of services I quickly want to build. I want to build a Twitter list, and this is just going to be a Twitter list of everyone that's here. So you guys are going to publish a message, and that's going to put all of you into a Twitter list. I also want to follow you all, so I can see what interesting things you're saying throughout the weekend, those sorts of things. I also want to see everyone's faces on the screen. So everyone that sends a message into this proponent network, your face is going to appear on the screen. It's going to look something like that. You'll be sending a message with your handleM, and the various services that pick those things up. So in case you missed it, gem install proponent is what you want to type in for those of you who have got laptops open. So I'm going to try and build an example, which can only go badly at 9 o'clock in the morning. And also, you probably can't see, but my screen is now flashing green rather than actually being black like what you see up there, which is quite concerning. So this is Vim. Can you guys all see that, guys and girls? So this is a config file. You can get some nice secret keys there, which I ask you not to abuse. We've got... It's good, isn't it? I will be counselling all of these quickly after the talk. So we've got two quick bits of configuration there. One for proponent, which just sets up with an Amazon access key and secret key and a Q region, in this case we're using EU Westrom. And then a Twitter set up a slightly different syntax, but similar, which sets up a consumer key and a consumer secret, and also an access token and access secret. Those are my personal access token and access secret. And there's a couple of other things down there which I'm going to use in a second. We've got a few different scripts. We're going to very quickly write. The first of these is the script for making lists. I'd like you guys to be my pair for the rest of this session, especially Eric, wherever Eric is, so he maintains the Twitter gem. That would be extra helpful. So we require this config on the left, and then we're going to also set an application name. And this is going to be Barucho14 lists. And we'll just do a put statement to say we're ready to go. And then we're going to listen to a queue. And we're going to call this queue handles. And when we get a message on here, or a handle, as it's going to be, we're going to do something with it. So we'll say adding to list handle. And then we're going to use our Twitter config that we've got. And we're going to say Twitter add list member. And the syntax for that is to take my Twitter handle and then the Barucho 2014 list and the handle. Simple. So that's now a script ready to run in our network. So you could pop this on Heroku, or we just pop it on EC2 machines on Amazon. If we, what's it called, lists. So if we run that, that's going to sit there. And if I didn't make any syntax errors, hopefully in a second, it will say that it's ready to go. Excellent. So that's a good start. So next we have a publisher. So this is something that's going to publish a message into the network. So here we're going to say require relative comfy again. We don't need an application named for just pushing things out. And if we say we're ready to go again. And this one is just a publisher. So it's just propono, publish, handles, and then a message. And actually I'm going to just say whatever the first thing I pass in to the script. I'm also going to say that we should do this synchronously, not asynchronously. So by default propono spawns new threads for different messages, which is probably a really rubbish default, but something we went with them that we can't really change very easily now. So that's our publisher. So we've got this list over here. And over here we're going to say publisher. And I'm going to try and add an account called advanced Ruby to the list. So this is a new project that I'm working on, some advanced Ruby tutorials. I'm going to be using this as my test account for this session. So we've got a list that somebody's added themselves to. And we're going to, good work, whatever that was, and we're going to see if we can push someone to this list. So what I'm going to do, I'm going to run this, really be publisher advanced Ruby. That's going to send a message up onto this, I'll look at the code just to show you, onto this handles topic that we've got here. Over here the list script here is listening for something called handles and when it gets something it's going to add this list member. So that's published advanced Ruby to handles via SNS. We can publish via lots of different things, TCP, UDP, or via straight up to SNS. And then over here we can see that's worked really well and somebody's already got on here nice. Please don't abuse my keys. And we can see that that's added advanced Ruby to the list. So hopefully if we refresh this we should see, there we go, advanced Ruby has been added to the list. So we've now got a service and we've got something that can publish messages out to the service. So let's do the same for following. So exactly the same script but I just want to follow the handle. So if we go back over here and we run that, we just need to change the application name. So if we run that, hopefully I'll say it's ready to go. And if you see over here, I'm currently not following this account. So you're ready to go if I run that. Now this message is going to get picked up by both scripts again. So it's just going straight back out there and the script over here is somebody else's picked up. Nice work, whoever that was. And that's published advanced Ruby. You can see here there's a nice little bit of different code going on. So each time a hash is generated for each message that's published and that hash is then available all through the stream. So you can see the B1 I've just posted has come there. And over here, hopefully, we're following somebody here and the other message hopefully gets picked up in a second as well. So who is this account? Let's get this person on the screen. Excellent. Whoever that is, I'm scared of you right now. Good. So there you go. That's also now following advanced Ruby. We're sitting in our network. Let's just check that it has actually worked. Although I am following this person. Yeah, great, I'm following this person. Cool. So those are two really simple ones. I want to just write a slightly more complicated one now. So what I want to do here is make a quick snar trap that's going to appear on the screen and when you tweet it's going to go and get... sorry, when you publish a message, it's going to go and get your face off Twitter and put it up on the screen. This is the use of the HTML5 event source library for this. So if we just quickly code up some images. So we're going to get a whole load of images that are just sort of small and fit across the screen that have no idea what it's going to look like on this res. And we can... So we're going to have in here a diff with an idea of images and we're going to say that we want an event source. So I don't know if you've used this. It's really cool. It's just like WebSockets built into HTML5. I hadn't used it until I was looking at how to do this talk and came across it. And you just say, our message equals a function that takes the arguments of whatever comes back from Snarcher. And we're going to say... So this, in clearly loadsport here, was jQuery in case you didn't notice that. So I can now say images.append and then we can say hsrc equals something e.data. So we're going to send data out from our Snarcher app just through WebSockets style things into here and that's going to hopefully add an image. I'll just make this a bit wider so you can see and you can get all of my secret keys. Cool. So we're going to require Snarcher and we're going to set the server to be thin and we're going to create a variable called connections, which is going to be in a way. And so that just sits within Snarcher's settings if you're not used to it. And then we're going to say we want just to get a root and we can just eie, whatever I call that, WebPage. And then we're going to get a slash stream and this provides a text slash event stream and in here we have a stream which is going to be a keep open stream and we're going to say settings.connections. So we're going to store that stream in this connection setting. So just to recap here, we'll render this page we will connect this event source called streams, which will get open stream and put a connection in. We're then going to require our config and we're going to say in a new thread just so this can execute alongside Snarcher proponio.listen2q and we need to add in proponio.config application name faces. We're going to say listen2q handles. Each time we get one of those we'll have a handle and we're then going to get an image SRC from Twitter which is user. So that will get the user and then it will I can never remember the syntax I think is that. That will get the image of that person and then for each of the connections we've got, we're going to say push in there some data and we want that to do that which is the syntax to push that through. That's not what I want to do. It could have been bad or it could have been good because I could have sampled one and it might actually work. So we've got some code some HTML, we've got Snarcher we've got a server, we've got a web page that renders we've got a stream that sits open we've got our config we've set an application name, we've started a new thread we're listening to this queue we're getting this SRC we go through all of the connections that we've got open and we render that out somebody has been sending interesting hitting some sort of rate limits good somebody is spamming me thank you to that very nice person so let's try that and see how many syntax errors I've got it's exciting so I've got that over here cool see if there's any JavaScript errors which there are not so let's publish something onto the advanced Ruby topic and see if this picks anything up great moment for patience when it either works or horribly falls apart with no idea of why oh wow it's picking something up is it going to put an image in there what do you reckon oh yes there we go amazing that's quite exciting cool hello so thank you cool so what you can see happening here all of these things are getting queued the reason my one didn't immediately appear there is because other people had managed to somehow get this code already and start putting messages in now I presume the reason everyone's got the code is because down here I've got this bitly link to anyone that hasn't noticed the bitly link and isn't inquisitive if you go there you'll find some code that looks something a little like this these are keys that are definitely going to get thrown away if you copy that pop that into a Ruby script and run that quickly and change where it says I hid to your own handle you should a few seconds later see me following you you should be added to this Twitter list over here and if we refresh a few things there we go we're starting to build this Twitter list 15 people in there already and we should start to get some faces appearing on here right who's the pony there we go man over there good work cool I'm going to leave this up for a second and everyone that's got a laptop open can have a quick play I really like people using the open source projects that I write and maintain if anyone wants to play around with the pony this weekend the best sort of concept of idea that comes up I'll get them to come up on tomorrow afternoon and you can demo it to everyone here if you want to and also anyone that does play I'm going to give lifetime access to all of the new advanced Ruby stuff I'm doing as well if you want to pair on any of that over the weekend as well I'd love to come and pair with you