SlideShare a Scribd company logo
1 of 12
Download to read offline
Streaming Geo
Coordinates from
MongoDB to your
iPhone App with
PubNub using
WebSocket SDK!
by Stephen Blum
Not long ago we partnered with a high-
standards online engineering broker (an
online listing service where you can post
engineering projects). The partnership
involved joint PR and blogging, however a
new opportunity/idea was presented. This
particular idea stemmed from a
commission listed on the broker’s website
which listed requirements for building an
integrated Real-time Map Service. We took
the opportunity and built a Ruby GEM with
a sprinkle of documentation and HTML5.

Continue through the slides for a quick start
guide to build an integrated real-time map
service.
For those of you who need a quick mini-guide to getting your MongoDB installed and running with
data sync streaming directly to your mobile app, you can follow this guide:
MongoDB Pipe GitHub Repository. It will show you how to download/install MongoDB and the
MongoPipe GEM.

Real-time Data Stream of Geo Coordinates

Lat/Long from MongoDB replicated to your iPhone App

The commission at the online workplace was posted as a $3,025 bounty. Rather than taking the
commission for ourselves, which involves building and delivering the solution in a private exchange,
we instead reviewed the specifications and requirements and we developed an open source
implementation that you can download and run for your live app today! MIT License, so you can use
this however you desire. We even created a GEM for you and made it easy to get started:
gem install mongopipe
Downloading the GEM is the first step in the process and next we’ll walk you through more details.
Actually now may be the time for you to watch the short video (next slide), so feel free to jump into
that now if you want a very brief demonstration and usage covering these points:

1.  Installing the Ruby gem and

2.  Executing the commands to setup MongoDB and

3.  Running the Pipe Daemon.

4.  Launching the Map Viewer.

5.  Finally inserting lat/long coords into MongoDB.

6.  Result is live-animated points on a map displayed on the iPhone.
The video will show usage of the MongoPubNubPipe gem. Source code is available via GitHub if you
want to see everything - MongoDB Pipe GitHub Repository
MongoPubNubPipe::Connect.new(...)	
MongoDB Geo Coordinates

This becomes the new interface that is available with mongopipe gem:



Usage of MongoPubNubPipe is available in later slides.
The video demonstrates an implementation of the connection between MongoDB and a mobile
device (an iPhone in this case). This application code and gem library will provide you a way to easily
add a live always-on map connection which allows you to send lat/long signals directly to the device
displaying the map with the specific Lat/Long DB written into MongoDB. This will cause the device
to draw an animated dot onto the screen of the device in real-time.

The dot that animates is triggered by simply writing to your MongoDB collection directly either
through the mongo console or through your RoR/Ruby Server Code. For example here is a MongoDB
Console Command that will cause a DB write, creating a Document, which then triggers the sync
with the consumer iPhone device that is rendering the map in real-time.
db.collection_name.insert({ latlon : [ 1.5, 2.0 ] })
gem install mongopipe	
Once you’ve written a Lat/Long coordinate into MongoDB collection, the process begins instantly
synchronizing with any connected iPhone. We where able to include several feature requests and
here follows the requirements:

When a new Lat/Lon document is inserted into MongoDB, stream the Lat/Lon data to a mobile
device is push data.

Use a Ruby or Node.JS Service to stream the data out of MongoDB as it is written in real-time.

Simple enough, yes, though it requires moving pieces. We simplified the process and built two
modules: one in Ruby and one in HTML5. We’ll walk through the methods for getting you started and how
to hook into the stream on your iPhone App. You can fast-track the tutorial and go strait to the
GitHub Repository or gem install mongopipe package for ruby.

GitHub Repository

MongoDB Pipe GitHub Repository
How it Works

MongoPipe is a new tool powered
by PubNub that streams your
MongoDB Documents from your
MongoDB Collection directly to your
iPhone App in less than 0.25 seconds
(real-time) using the PubNub Real-time
Network. Your iPhone app opens an
always-on TCP Socket Connection to
PubNub while a dispatch process runs
on your MongoDB server via Tailable
Cursors to catch inserted documents.
The data is streamed and brokered via
PubNub Network directly to your
iPhone App in real-time.
mongod	
require 'rubygems'	
require 'mongopipe'	
	
## ------------------------------------------------------
## Pipe MongoDB for Inserts	
## ------------------------------------------------------
MongoPubNubPipe::Connect.new(	
:puts_usage => true,	
:publish_key => 'demo',	
:subscribe_key => 'demo',	
:db => 'test',	
:collection => 'cap_collection',	
:callback => lambda{ |doc|	
## Optional Callback Called on Doc Insert	
## Remove :callback if you don't need it.	
puts(doc)	
}	
).pipe()	
MongoDB Tailable Cursors

The ruby GEM mongopipe utilizes the tailable
cursor interface provided by MongoDB
Core. Document Data is then piped directly
through the PubNub Network which uses a
direct broadcast synchronization socket
with the mobile app.

Next we’ll show you what the process is to
get the mongopipe running on your Ruby
Server.

Make sure MongoDB is running

Next open a text editor and copy/paste the following
monogopipe example.













Save this to a file pipe.rb for example then execute it.
Ruby pipe.rb
Step 1: Open Your Browser to Show PubNub Pipe Console	
This will connect directly to MongoDB and print usage guide on next steps. The video covers only a
demonstration of this process. Here is a sample output of what may be provided via the puts(doc) output:
> Open http://www.pubnub.com/console?channel=test.cap_collection	
Step 2: Open Demo Map on Your Phone	
> Open http://goo.gl/HAqAv#test.cap_collection	
Step 3: Insert Test Data	
> ./mongo	
> Use test	
> db.cap_collection.insert({ latlon : [ 1.5, 2.0 ] })
Remaining Details

This blog entry was intended to give you a quick
skim over the details on how the mongopipe ruby
gem works and what is involved in coordinating
the embeddable mobile HTML5 animated map.

If you have any more questions please
tweet @PubNub directly.

You may be curious about the connectivity
mechanism between your iPhone App and your
MongoDB Sever. Checkout the PubNub
WebSocket Reference below to see the
transport mechanism utilized.

Thank you for reading!
PubNub WebSocket Reference

The MongoDB Pipe uses the PubNub Network WebSocket interface which provides an always-on
socket connection to your iPhone app. The PubNub Network WebSocket acts as a broadcast
receiver and syncs directly to your mobile device in real-time from your MongoDB server via
MongoPipe.

Following is an example of how the Map app implements the socket:
// Create Socket Connection	
var socket = new WebSocket(	
'wss://pubsub.pubnub.com/PUBLISH_KEY/SUBSCRIBE_KEY/CHANNEL'	
);	
	
// Set Message Receiver Function	
socket.onmessage = receiver;	
	
// Receiver Function Prints Data Result	
function receiver(evt) { console.log(evt.data); }

More Related Content

Similar to Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using WebSocket SDK

Microservices in Golang
Microservices in GolangMicroservices in Golang
Microservices in GolangMo'ath Qasim
 
Meteor presentation
Meteor presentationMeteor presentation
Meteor presentationscandiweb
 
Pwa is the future. The Presentation I gave at PWA event
Pwa is the future. The Presentation I gave at PWA eventPwa is the future. The Presentation I gave at PWA event
Pwa is the future. The Presentation I gave at PWA eventAhmed Kaludi
 
Why You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API DevelopmentWhy You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API DevelopmentDevenPhillips
 
What is Codename One - Transcript.pdf
What is Codename One - Transcript.pdfWhat is Codename One - Transcript.pdf
What is Codename One - Transcript.pdfShaiAlmog1
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGrant Goodale
 
Building an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoBuilding an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoJosh Justice
 
Get started with meteor | designveloper software agency meteor prime partner
Get started with meteor | designveloper software agency   meteor prime partnerGet started with meteor | designveloper software agency   meteor prime partner
Get started with meteor | designveloper software agency meteor prime partnerDesignveloper
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)alloy020
 
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnect
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnectIntro to IBM Bluemix DevOps Services, an open lab for IBM InterConnect
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnectLauren Hayward Schaefer
 
iLabs Toolbox Javashare 2008
iLabs Toolbox Javashare 2008iLabs Toolbox Javashare 2008
iLabs Toolbox Javashare 2008rmzdotno
 
PhoneGap Framework for smartphone app developement
PhoneGap Framework for smartphone app developementPhoneGap Framework for smartphone app developement
PhoneGap Framework for smartphone app developementTrieu Nguyen
 
Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3Bruce Pentreath
 
Hybrid Apps in a Snap
Hybrid Apps in a SnapHybrid Apps in a Snap
Hybrid Apps in a SnapPaulina Gallo
 
Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGapRamesh Nair
 

Similar to Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using WebSocket SDK (20)

Microservices in Golang
Microservices in GolangMicroservices in Golang
Microservices in Golang
 
Meteor presentation
Meteor presentationMeteor presentation
Meteor presentation
 
Meteor
MeteorMeteor
Meteor
 
Pwa is the future. The Presentation I gave at PWA event
Pwa is the future. The Presentation I gave at PWA eventPwa is the future. The Presentation I gave at PWA event
Pwa is the future. The Presentation I gave at PWA event
 
Why You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API DevelopmentWhy You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API Development
 
What is Codename One - Transcript.pdf
What is Codename One - Transcript.pdfWhat is Codename One - Transcript.pdf
What is Codename One - Transcript.pdf
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
 
Building an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoBuilding an App for Mobile and Web with Expo
Building an App for Mobile and Web with Expo
 
Get started with meteor | designveloper software agency meteor prime partner
Get started with meteor | designveloper software agency   meteor prime partnerGet started with meteor | designveloper software agency   meteor prime partner
Get started with meteor | designveloper software agency meteor prime partner
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)
 
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnect
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnectIntro to IBM Bluemix DevOps Services, an open lab for IBM InterConnect
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnect
 
iLabs Toolbox Javashare 2008
iLabs Toolbox Javashare 2008iLabs Toolbox Javashare 2008
iLabs Toolbox Javashare 2008
 
HealthyCodeMay2014
HealthyCodeMay2014HealthyCodeMay2014
HealthyCodeMay2014
 
PhoneGap Framework for smartphone app developement
PhoneGap Framework for smartphone app developementPhoneGap Framework for smartphone app developement
PhoneGap Framework for smartphone app developement
 
Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3
 
Mdb dn 2017_16_iot
Mdb dn 2017_16_iotMdb dn 2017_16_iot
Mdb dn 2017_16_iot
 
Hybrid Apps in a Snap
Hybrid Apps in a SnapHybrid Apps in a Snap
Hybrid Apps in a Snap
 
Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGap
 
Hack Rio/OS
Hack Rio/OSHack Rio/OS
Hack Rio/OS
 

More from PubNub

Streaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.jsStreaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.jsPubNub
 
Defining the IoT Stack
Defining the IoT StackDefining the IoT Stack
Defining the IoT StackPubNub
 
What the heck is a realtime app?
What the heck is a realtime app?What the heck is a realtime app?
What the heck is a realtime app?PubNub
 
TrackPad Destroyer
TrackPad DestroyerTrackPad Destroyer
TrackPad DestroyerPubNub
 
Real-Time Stats for Candy Box
Real-Time Stats for Candy Box  Real-Time Stats for Candy Box
Real-Time Stats for Candy Box PubNub
 
Lightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNubLightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNubPubNub
 

More from PubNub (6)

Streaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.jsStreaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.js
 
Defining the IoT Stack
Defining the IoT StackDefining the IoT Stack
Defining the IoT Stack
 
What the heck is a realtime app?
What the heck is a realtime app?What the heck is a realtime app?
What the heck is a realtime app?
 
TrackPad Destroyer
TrackPad DestroyerTrackPad Destroyer
TrackPad Destroyer
 
Real-Time Stats for Candy Box
Real-Time Stats for Candy Box  Real-Time Stats for Candy Box
Real-Time Stats for Candy Box
 
Lightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNubLightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNub
 

Recently uploaded

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using WebSocket SDK

  • 1. Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using WebSocket SDK! by Stephen Blum
  • 2. Not long ago we partnered with a high- standards online engineering broker (an online listing service where you can post engineering projects). The partnership involved joint PR and blogging, however a new opportunity/idea was presented. This particular idea stemmed from a commission listed on the broker’s website which listed requirements for building an integrated Real-time Map Service. We took the opportunity and built a Ruby GEM with a sprinkle of documentation and HTML5. Continue through the slides for a quick start guide to build an integrated real-time map service.
  • 3. For those of you who need a quick mini-guide to getting your MongoDB installed and running with data sync streaming directly to your mobile app, you can follow this guide: MongoDB Pipe GitHub Repository. It will show you how to download/install MongoDB and the MongoPipe GEM. Real-time Data Stream of Geo Coordinates Lat/Long from MongoDB replicated to your iPhone App The commission at the online workplace was posted as a $3,025 bounty. Rather than taking the commission for ourselves, which involves building and delivering the solution in a private exchange, we instead reviewed the specifications and requirements and we developed an open source implementation that you can download and run for your live app today! MIT License, so you can use this however you desire. We even created a GEM for you and made it easy to get started: gem install mongopipe
  • 4. Downloading the GEM is the first step in the process and next we’ll walk you through more details. Actually now may be the time for you to watch the short video (next slide), so feel free to jump into that now if you want a very brief demonstration and usage covering these points: 1.  Installing the Ruby gem and 2.  Executing the commands to setup MongoDB and 3.  Running the Pipe Daemon. 4.  Launching the Map Viewer. 5.  Finally inserting lat/long coords into MongoDB. 6.  Result is live-animated points on a map displayed on the iPhone. The video will show usage of the MongoPubNubPipe gem. Source code is available via GitHub if you want to see everything - MongoDB Pipe GitHub Repository
  • 5. MongoPubNubPipe::Connect.new(...) MongoDB Geo Coordinates This becomes the new interface that is available with mongopipe gem: Usage of MongoPubNubPipe is available in later slides.
  • 6. The video demonstrates an implementation of the connection between MongoDB and a mobile device (an iPhone in this case). This application code and gem library will provide you a way to easily add a live always-on map connection which allows you to send lat/long signals directly to the device displaying the map with the specific Lat/Long DB written into MongoDB. This will cause the device to draw an animated dot onto the screen of the device in real-time. The dot that animates is triggered by simply writing to your MongoDB collection directly either through the mongo console or through your RoR/Ruby Server Code. For example here is a MongoDB Console Command that will cause a DB write, creating a Document, which then triggers the sync with the consumer iPhone device that is rendering the map in real-time. db.collection_name.insert({ latlon : [ 1.5, 2.0 ] })
  • 7. gem install mongopipe Once you’ve written a Lat/Long coordinate into MongoDB collection, the process begins instantly synchronizing with any connected iPhone. We where able to include several feature requests and here follows the requirements: When a new Lat/Lon document is inserted into MongoDB, stream the Lat/Lon data to a mobile device is push data. Use a Ruby or Node.JS Service to stream the data out of MongoDB as it is written in real-time. Simple enough, yes, though it requires moving pieces. We simplified the process and built two modules: one in Ruby and one in HTML5. We’ll walk through the methods for getting you started and how to hook into the stream on your iPhone App. You can fast-track the tutorial and go strait to the GitHub Repository or gem install mongopipe package for ruby. GitHub Repository MongoDB Pipe GitHub Repository
  • 8. How it Works MongoPipe is a new tool powered by PubNub that streams your MongoDB Documents from your MongoDB Collection directly to your iPhone App in less than 0.25 seconds (real-time) using the PubNub Real-time Network. Your iPhone app opens an always-on TCP Socket Connection to PubNub while a dispatch process runs on your MongoDB server via Tailable Cursors to catch inserted documents. The data is streamed and brokered via PubNub Network directly to your iPhone App in real-time.
  • 9. mongod require 'rubygems' require 'mongopipe' ## ------------------------------------------------------ ## Pipe MongoDB for Inserts ## ------------------------------------------------------ MongoPubNubPipe::Connect.new( :puts_usage => true, :publish_key => 'demo', :subscribe_key => 'demo', :db => 'test', :collection => 'cap_collection', :callback => lambda{ |doc| ## Optional Callback Called on Doc Insert ## Remove :callback if you don't need it. puts(doc) } ).pipe() MongoDB Tailable Cursors The ruby GEM mongopipe utilizes the tailable cursor interface provided by MongoDB Core. Document Data is then piped directly through the PubNub Network which uses a direct broadcast synchronization socket with the mobile app. Next we’ll show you what the process is to get the mongopipe running on your Ruby Server. Make sure MongoDB is running Next open a text editor and copy/paste the following monogopipe example. Save this to a file pipe.rb for example then execute it. Ruby pipe.rb
  • 10. Step 1: Open Your Browser to Show PubNub Pipe Console This will connect directly to MongoDB and print usage guide on next steps. The video covers only a demonstration of this process. Here is a sample output of what may be provided via the puts(doc) output: > Open http://www.pubnub.com/console?channel=test.cap_collection Step 2: Open Demo Map on Your Phone > Open http://goo.gl/HAqAv#test.cap_collection Step 3: Insert Test Data > ./mongo > Use test > db.cap_collection.insert({ latlon : [ 1.5, 2.0 ] })
  • 11. Remaining Details This blog entry was intended to give you a quick skim over the details on how the mongopipe ruby gem works and what is involved in coordinating the embeddable mobile HTML5 animated map. If you have any more questions please tweet @PubNub directly. You may be curious about the connectivity mechanism between your iPhone App and your MongoDB Sever. Checkout the PubNub WebSocket Reference below to see the transport mechanism utilized. Thank you for reading!
  • 12. PubNub WebSocket Reference The MongoDB Pipe uses the PubNub Network WebSocket interface which provides an always-on socket connection to your iPhone app. The PubNub Network WebSocket acts as a broadcast receiver and syncs directly to your mobile device in real-time from your MongoDB server via MongoPipe. Following is an example of how the Map app implements the socket: // Create Socket Connection var socket = new WebSocket( 'wss://pubsub.pubnub.com/PUBLISH_KEY/SUBSCRIBE_KEY/CHANNEL' ); // Set Message Receiver Function socket.onmessage = receiver; // Receiver Function Prints Data Result function receiver(evt) { console.log(evt.data); }