Outside the (Web) Box: Using Ruby for Other Protocols

Video in TIB AV-Portal: Outside the (Web) Box: Using Ruby for Other Protocols

Formal Metadata

Outside the (Web) Box: Using Ruby for Other Protocols
Title of Series
Part Number
Number of Parts
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
Ruby on Rails is a widely used web framework, using HTTP to serve users web pages and store data to databases. But what about serving different types of clients? Is it possible to integrate Rails with other protocol types to talk to other machines? Is it efficient? How would it work? I'm going to share my team's approach integrating a Ruby on Rails application with automation and warehouse hardware, such as barcode scanners and Zebra printers.
Computer animation Different (Kate Ryan album) Communications protocol
Computer animation Code Sampling (statistics)
Data management Software Multiplication sign Computer-assisted translation Physical system
Computer animation Internetworking Moment (mathematics) Computer hardware Mereology Twitter Physical system
Point (geometry) Arm Scaling (geometry) INTEGRAL Multiplication sign Web application Spring (hydrology) Computer animation Software Web-Designer Different (Kate Ryan album) Computer hardware Belegleser
Complex (psychology) Process (computing) Computer animation INTEGRAL Virtual machine Energy level Mereology Communications protocol Physical system
Computer animation Software Web-Designer Software developer Multiplication sign Computer hardware Lebesgue integration Physical system
Authentication Game controller Server (computing) Feedback Web browser Cartesian coordinate system Mereology Computer Event horizon Data transmission Computer animation Software Lastteilung Middleware Communications protocol Identity management Physical system
Suite (music) Decision theory Mereology Cartesian coordinate system Ruby on Rails Formal language Process (computing) Computer animation Different (Kate Ryan album) Energy level Software framework Netzwerkdatenbanksystem Communications protocol
Laptop Computer animation INTEGRAL Different (Kate Ryan album) Network socket Computer hardware Virtual machine Software testing Lebesgue integration Library (computing)
Computer animation Network socket Interpreter (computing) Set (mathematics) Quicksort Computer IP address Library (computing)
Dataflow Server (computing) Functional (mathematics) Software developer Database Client (computing) Web browser Connected space Computer animation Network socket Order (biology) Computer hardware Quicksort Social class Library (computing)
Server (computing) Socket-Schnittstelle Computer file Client (computing) IP address Number Connected space Computer animation Web-Designer Network socket Representation (politics) Object (grammar) Library (computing) Social class
Server (computing) Socket-Schnittstelle Computer file Range (statistics) Virtual machine Client (computing) Instance (computer science) Multilateration IP address Connected space Subset Type theory Word Computer animation Software Personal digital assistant Different (Kate Ryan album) Logic Network socket Order (biology) Quicksort Belegleser Library (computing)
Server (computing) Message passing Process (computing) Computer animation Demo (music) Sound effect Error message Random graph
Message passing Computer animation Network socket Sound effect Representation (politics) Bit Client (computing) Object (grammar) IP address Number
Computer animation Pattern language Function (mathematics) Connected space
Computer animation Integrated development environment Software Order (biology) Virtual machine Energy level Cuboid Belegleser Connected space
Process (computing) Computer animation Computer configuration Virtual machine Cartesian coordinate system Physical system Number
Demon Presentation of a group Game controller Group action State of matter Code Multiplication sign Sheaf (mathematics) Image processing Web browser Mereology Perspective (visual) Rule of inference Formal language Network socket Computer hardware Lebesgue integration Endliche Modelltheorie Belegleser Address space Arm Demo (music) Parallel port Database Instance (computer science) Cartesian coordinate system System call Connected space Message passing Process (computing) Computer animation Personal digital assistant Family Communications protocol
Programming language Game controller Arm Identifiability File format Code Electronic program guide Line (geometry) Cartesian coordinate system Formal language Element (mathematics) Message passing Computer animation Logic String (computer science) Network socket Pattern language Right angle Quicksort Computer-assisted translation Error message Middleware
Demon Server (computing) Process (computing) Computer animation Demo (music) Personal digital assistant Real number Weight Game theory Cartesian coordinate system
Socket-Schnittstelle Service (economics) Divisor Code Multiplication sign Letterpress printing Open set Information privacy Mereology IP address Product (business) Term (mathematics) Network socket Formal verification Computer hardware Energy level Cuboid Software testing Software framework Belegleser Information security Closed set Software developer Structural load Database Instance (computer science) Cartesian coordinate system Message passing Process (computing) Computer animation Software Web-Designer Figurate number Quicksort
Complex (psychology) Server (computing) Group action Arm Local area network Software developer Multiplication sign Virtual machine ACID 1 (number) Water vapor Connected space Message passing Process (computing) Software Meeting/Interview Web-Designer Personal digital assistant Logic Telecommunication Quicksort
this is also a long and she th of the and the guys
at finding the now and suffering here from New York I think you all for coming to see me speak of this I 1st aerials con so this is pretty saying I will nerve-racking I will say and I just before this happened I had to run back to my ear you incoming labels because it is completely forgotten the title of is made them so probably can only go up from here so and so I'm here to talk about how we can integrate rails with different but had 2 protocols on so yes so start isolated like I
said finding out what is my Twitter handle and I can have a handle on severely questions afterward maybe don't get answered by to me and saying and then on there's going to be some code samples I finally get how do not and and
so little about me i work at a chemical blueprint you guys have probably seen are on Her heard our podcast sponsorships you here's so I mean I work on the warehouse
management system team so what that means is that all the software that's built within the warehouses for our on probably is that something bad
my team helps build and so that things like this don't happen I another
important fact about me is that I have attacked his it was done as bad and I like most cat owners the spend about 90 % my free time to the pictures of him once leads the I some notable
achievements about myself on
the day that the Internet went down pipe week that
went viral this was really exciting for me because I'm not even really big 20 there I had 400 engagement and ended up on Twitter moments and another notable achievement
is that I was part of a team that introduced
automation and hardware into bluey
brains warehouse system of last summer
and so that's what I'm going to talk to you guys about is that how we can integrate Ruby and rails and arms get outside the web development scope and actually start integrating with some hardware so for some you back in
time by to spring of last year
or so really last year blueprint we decided that we wanted to introduce on a lot of automation into you arts software and so on up until this point everything that we were doing was Web Development based so we had a lot of difference on web applications that we were interacting with reason rails on in so we started realizing OK if we want to help the company scale we're going to have to integrate with these printers in the scanners that we're working with the warehouses the so we have to start thinking about OK we had surpassed questions about on what this would look like then why have a
scenario where you know we have on our were not being able to handle the latency that needs to be handled or on the different connections and so we wanted to we started looking at a rails the right tool for the job on his redirect tool for the job or we can have to do this in Python we can have to rewrite everything to eating multithreading on there's a lot of questions that we needed to observe on because these new on because this new part of that we're introducing it was really adding a layer of complexity to a systems
on so he and here's a high-level on high level is is what I'm going to go over and talk about and so 1st Cyrillic go over the dividend to propose there are we need to be using on in this talk about how you can integrate movie with machines and then I'm gonna talk about how you can integrate the harbor with rail system the 1st protocols
I so at the time like I said we were mostly web development are we weren't doing a lot of suffer development in the sense of like integration with hardware on an automation and so we had a lot of we all our software was also and speak http but we what we needed was from a system that could be TCP which is what the on what is the harvest of so 1st of all
we that's that's status back on and look at what is an HTTP request and how Israel's handle that request as about we have a
browser on the browser makes a request on the IP is resolved by Indian as on in the middle we might have a caching layer are in my region alone to a load balancer and then at over the rails application it hits are application server Pollock who married unicorn on it goes through the rock middleware so rack is are passing it for onerous filtering out standard there's on the authentication where identity trails events against rather and then haven't recitalists so what is TCP this was a different protocol that we speak of so TCP I was something that was introduced in 1981 by on it with the 10 of being used with the US Department of Defense on so as we can see here is the transmission control protocol and is intended for use as a highly reliable host-to-host protocol between host a packet-switched computer system er computer not and interconnected systems of such networks on and that's part of the Odyssey that was introduced and so for those of you that don't know R.
C. that stands for a request for comment so that's a fairly common on the way that people are introducing new ideas in our computers and software eyes so that they can draft this idea that they have and they can receive feedback from interested parties are so how is the
TCP different from http
that's actually part of the same network model and so what we have is that about their protocol suite and so the application of level which is http and beneath that we have built a lower level of layer which is the transport layer and not is hard TCP where so going back like I said before
we had started on we started looking at the different languages and frameworks that we need to move over if we need to support this automation on so consumer we actually decided that Ruby on Rails were pre job or what we needed to deal on there's a lot of reasons for this by by mostly we were aware when we're making these design decisions that we could support these lower connections on so we are so we started working and
testing we started figuring out how we can integrate that aren't used movie and rails and integrate with the the different halves of hardware so this is an example of where it will take in the warehouse is we had our laptops running a local host connecting with the different devices and just I figure out what works and so on so yes endowment of
about Ruby and its integration with machines and how we discovered that we can interfere with our rail systems transceivers about those of you that don't know really has a socket library that you can use on
it's in it's in a library so when you install Ruby it's already available for you on interpreters of you don't
know I choose another snippet from the odyssey that I spoke of before but a socket is essentially just on a set of 2 values on an IP address and port and on that and what they do is they distinguish a unique point and on within any sort of computer I'm so really is the socket
library has class called TCP socket built on the base I saw the class and so it has all the functionality that we needed to open a socket to any sort of device any sort of server usually or Howard connection how flow data looks is we would have a client browser on the client makes a request to the Real server and then we make a poster update on us an update to a database and I said this is that it as far as the development goes this is a fairly common flow data and so on will we want it was we wanted a client that was speaking to a printer so how would we do that if it's not speaking HTTP and it's always been TCP Isely's overstocking and
so on in order to community with this hardware a TCP socket needs to be established so let's look at what that might look like review 5 so like I
said we use the island the socket library so we just important in in the file that were the descriptor reasoning but like I said before are on TCP IP TCP sockets have an IP address and they aren't at work so we have to define this new but we've created as a socket object I what is the representation of the socket and we define its IP and it's on port number by in the writing to the socket and they were disclosing at so on the other side of is if we needed to our have a TCP server that supports socket connections from on from a TCP socket we also have a TCP server class that's available in the on the road libraries are a library so like I said before this
is a fairly common full data and whether you're in web development in the client to server and it makes an update to database but and
so how do we In bomb establish this connection between the client server are in TCP so really it might look like this so we have our we require the soccer Library again I we've established we create the a on the instance of a socket earned on the server on so we don't need to pass an IP because wherever the eyes server is restarted its on whatever machine that it on so in this case it would be will host or whatever IP address the you're running on which is a port but when you're choosing a port there's a range of words you can use like some thousand 40 50 thousand or something like that so you just pick a port and till tostada surround the on OK and so then the server around once it's it's running it's listening for any kind connections and so this 1 I is doing a very jealous guarding against and he's sort of a bad sockets so it's just a set on receiving any socket it's acceptance accepting it I it's reading the it's acknowledging that it's received a client and then it's reading the client outputting it and then it was a socket but so these are a few
examples of the different types of machines that you can use all with this library so deal logic is the scanners on the company that makes scanners zebra is what is your partners are and so those that had been received on the be files which are going into a little bit later and a television is the company that builds are are software for our shoes order so houses have about that a little bit later
somebody demo but what I
find relationship looks like so so small some of error on kind of can receive
effect and so so 1st we can look at why on the server looks like I had to like I said before we are on were choosing a port and then we're just starting a process in which were listening and then we are reading the message in work was in so we can start at I just and we can just choose a random network so let's say 4 thousand so now
on so now we have on other side let's look at what the so on but with the clients cripple look like so it's a little bit smaller like we said it is always and then it's closing it after its message and so we are the client and so when you pass it an IP address i which is little host the port number that were trying to read and then a message so say who rails effect so as we can see here
on we receive the client we up at the message and then we are closing this same and so this really object is the representation of a socket that it's been on
established the so we can do it again we write another and turn arrested firms but so as you see
here it's outputting on a different some connection patterns on closing such as well so so that's how you use
rude to communicate intrinsically about so now
on the the but guess so now I so fast forward to winter of last year 1 and so what on so what we started so as we started to what we already started building on a lot of the software to support the different connections and so it's started integrating it we have printers and scanners either were starting to introduce into a production environments on so then we had in this feast I'm in
so what level is doing is that we wanted to introduce this I shoes on a machine to ah warehouses and so the way issues are works is you have a so you have a package that gets on a conveyor belt on there's an overhead scanner and it goes through it scans something on the box in 9 editions order are diverted into only whatever land depending on what the on the machine has what the machine is ready the on so because of
this and we will have this huge machine it's obviously very limited sense if we wanted to make sure that we were integrating with RL systems smartly on and so numbers have about how what are the different options that we can do that so that we have on asynchronous are processes in RL system so that we have we can make sure that everything is working on as efficiently as possible an so we wanna make
sure that the like a civil war when make sure that things are working as efficiently as possible and then nothing is on being blocked by anything else so we don't in this way we don't the Rails application to be doing too much on so I think that's I think in any by thank system that you're designing you never want put everything in the same process that just doesn't make any sense that's a multithreading foreign on things that psychic and so
on so we did something what are some animals what problems the we have something called that identical non-blocking integration and so on it's kind variant of nonblocking I O bond we have so we have a Rails application on and we can have a process that's running simultaneously that can handle that on the connections to the hardware and then on top of that we can have another simultaneously on process that handles on the updates to databases and what not so that's what's happening from the brothers perspectives of you have something where we are to be going from browser to print all of those processes are a not blocking we have from like we have a state asynchronous behavior so that we can on move officially as possible on so as a you'd like as a before on a user example would be we might have a browser and browser needs to print something out from the printer and so we can do this because I it weird is that before like we learned the 1st section that http is browser that's pretty standard are in and TCP is the printer and so because axons because simple protocol there's no way that we do this so how would we totally implementers so we could do something like this we have a browser on which makes an update to urban sigh makes it up was repressed or else controller on and and so the rails controller incapable worker i in the purposes of this demo on earth in this part of this presentation on using psychic the sparse and on and then to the worker well can open up a TCP socket it to this to the printer and so in Escobar Rails application we would have something like this where onto still labels controller and then we have another worker or just adopt once the on what's the action the request has been made and so this is the co it's pretty standard rules code we have on their create on Post Alley created this label arm and then after we create the label we have a printer worker that case off a job at Parsons EPL and so on so many go into whether PL is a little bit later on and then this is a stupid of code that we would see from the prior work on this so we've created a cue for are devices that to handle any sort of on the hardware that we might need to communicate with in this case we are opening the cocksucker enclosing it in the same work what after for the because of the purposes of this the presentation are so another example that we might need is that we have scanner and the scanner needs to make an update to a database but the scanner is the TCP in the database is you know it has its own so how would we do that I'm so something that we might want to do it is without a scanner bond in the scanner it is are so imaging process this was into a scanner on in so for those of you that don't know a diminishes the background process that's listening on the most popular example would be like melody if you e-mail an incorrect address 8 kids out there on a call back and it returned announces this person does exist circulated the Ramallah whatever on so yes we would do in the listening to the scanner on and then the call that on when the team receives a scan is it a case of another worker on and worker reason updated database answer this is what it would look like in this scope Rails application so we decide a scanner worker on and then we have a separate process that runs parallel to rails are all which is the demon so we have our real server on and then in separate since we have this team and which is listening for scans on its overcoat perspective this is why it might look like we have on just a step that we I've written on and it created takes up the daemon process on and then we have a the demon and so every time it receives a scan 88 to stop the scan worker and it performs the updated database that we need on
so another thing about integrating with rails is that a lot of these different devices speak different protocols so for instance be scanner on this the scanner the printer like I said before speaks on it receives a different of a specific language but then when you scan that same label you don't receive the same thing back so and you might not receive and and as far as the skiers go you might have 3 different models of a scanner and all Member are sending differ protocols on the message so it gets a little bit confusing on diverse Volokh instead all
is on as Eva programming language on its legal definition and the control language so this is an example of a zebra arm as EPA strength so it's you think it's sort of like HTML you can deliver to in a string born it's just a simple string on and so if there is a certain element that's offers there's a syntactical error on it won't format right or it might not even display correctly all or not at all the prevents only fell on so it's just a guide does recognize is on sensible patterns this is at the top we have to use the mouse yet again at the top we have on the start of the string and during either some stuff with formatting and how big the taxes in B we have the answer maker a barcode of barcode QR on and for data this is tells the printer further scanner what the prayer hey I have some of the data that I'm gonna be passing to you and so this is a sort of this is an example of a message that we might receive from a printer so looks totally different we could be scanning the exact same thing that pre-adjusted out isn't is a completely different message so the 1st line we have all the messages scanner and then on the 2nd line we have our own we have an identifier the prior and then the line we have some other data that we we don't need are so
highly handle this because we don't want all this weird logic that isn't really on applicable to the rails application sprinkled all over the place on so the solution of this would be to have some shared code that axes middleware so that the minute that you receive the message from the TCP socket on deposit accordingly or it sends out accordingly and on access middleware so that once the the message gets to the application there is no ambiguity about you know what what is this message was why does it coming from harm is this even you know is this even saying what we think it is I am a cat so I mean
do a demo 5 so all those
processes that I just started that I was just talking about about having the on the device the running of the demon and then the Rails application how we show that all Tuesday and weighted everything's going work on a case a real server Oliver demon and
then we use netcat to be here with the game OK so 1st asks for her but that so
that's apparently labels In the labels so it creates an labels on could a yet yet do that a pet of but very to creditor labels where levels about signing 2 volunteers to give me your name and your title affect yes a here in the uh so that can that that so now making it a label on his only size we have so unintended was below a smaller on any 1 another yes grant but I which is and what's the title your dad that and to so now we have 2 labels that we printed out I'm so it's a at our are labels are labeled dashboard so before we had time to before we created 3 labels on their adjustment is created on now we have to print labels make infrared Ahmanson understand where these labels these it can the the way to bumps on this analogy fresh and so I scan minds label endowments labeling of data in the database and so now can now it's scan crimes label watch at and now both pregnant have skin labels the terms of the their labels and what I should
put some sort of hashtag use but forgot figure but would so yes so that is and that's example of how you can use rails and have on simultaneously running processes to make sure that you have a flow of like a workflow on like what we need in our in warehouses on so some obstacles that we had overcome but so 1st of all I not all hardware so that I can have multiple sockets open at the same time so that might not seem like a big deal but when you start to scale and you start by distributing load on there is that starts the problem because you wanna make sure that you are anticipating what is going where on so you don't want something to be sending a message to 1 device but Atari connected to another instance and then you have a silent fail because these are these are lower levels and so when we do send a message on were not necessarily getting a verification a not us er they got their on so keeping up persistent socket open on some frameworks don't don't support that so in the example that I gave I am creating of I'm opening socket and closing in on we might have an instance where we want to the open and so it would be we can do that found within the Rails application because we nothing supporting died on process that was 0 1 while it's open on and then privacy if we need security here obviously I'm so if there are also some hosting services that don't allow open sockets on on on on private to private network so for instance we have so why this matters is we have our own and we have devices that are in the warehouse on they can be on a public network because then anyone in in uh on the other side country in either i if if they know the IP or worse they just guess the IP address they just start sending messages were and we don't want that so we need to keep them on a private network and because they need to be on a private network we need to have hosting services that support open sockets to private networks and then testing so testing is out my fear things about development process by I love reason testing writing tests I make it has passed and so it's easy and web development to stay within the scope of your art when application in your code but when you're starting work hardware on automation testing is in its everything that you need on the lots of factors that go into the on the success of something in production so something it is ridiculous is the thing was unplugged toward that there are other corners along that it doesn't reached outlet the Ethernet has been is broken and others a lot of stuff that you need to anticipate and so on we aren't so manual testing is extremely important when you start integrating with hardware on so everything to and of my talk but I'm happy to say that these are the offer that we created is being used in blue up librans warehouses all across the country on introduction and it's being used to deliver parts of Italy has written here on no idea but I've been used to deliver a box is all over the country on this is also
way that we did this and we're really excited and I'm thinking think that my message to you guys is that I would really like you to you as web developers on just really think outside the scope of what development of what we can do how can integrate things on and there's a lot of really good something you would read braille so I encourage you to that and at
the end if end and yes and he said i with the as far as I'm keeping the the printer is on a private network could you just have to be on the server that we're working with on a local network the answer is yes I by just yeah arm but just maintaining software within a facilities is like a whole yeah you know and the realm of complexity so on that a possibility but it would just be a little bit difficult because then we have to physically maintain this suffer that's running on a local network of the this should have so the acid would been due to water made by our communication between devices that that only take 1 of the only take 1 connection by its it's pretty easy because even know of the business logic makes that really easy so we have warehouses we have 3 warehouses right now on each warehouse that's so let's see so each warehouse has a sort of machine the story machines action the ones they only can take 1 socketed time so we just have a process that handles that machine per facility so that's really it's not always that easy but in our case that which I this but not he asked if a so I will just only Iberia the ERB to render any of the city partner we haven't done I'm sure that's might be in the future by we don't preview any of those details as far as like rendering them as the gpls on you know other ways to do that but it's not move on the ass if if this is on the same the planned pipeline if we had any problems on if we had incomes maintain those targets we have so it is but such as adaptive process it's all the different so we use blue-green deployments to make sure that there are no there's no downtime on and so that means insurance diets yeah but there's no doubt and that's how we saw that that it's not a matter of if you have any questions feel free to come to fine after it clearly and that major offended analysts our manners of matter but it is a matter coming i and j is the last of the
old saying no so