a solid back end for a solid qt mobile application€¦ · © 2013 the qt company a solid back end...

50
© 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

Upload: others

Post on 17-Aug-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2013 The Qt Company

A Solid Back End for a Solid Qt Mobile Application

Page 2: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

About Me

Page 3: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Lauri Nevala

• Over ten years of experience in creating web and mobile based applications

• Working in Qt Cloud Services team at The Qt Company

nevalau nevalla nevalla

Page 4: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Awesome mobile applications…

Page 5: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

…and they all need back-end systems!

Page 6: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

How do you implement your back end solution?

Page 7: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

You have an idea

BUY AND SETUP HARDWARE

INSTALL OS

DEFINE ACCESSCONTROL

SETUP ANALYTICS

INSTALL SOFTWARE

BUILD

JUST START BUILDING

APP APP

X

Page 8: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

PaaSPlatform as a Serv ice

Page 9: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

What is PaaS?Applica'on*

Data*

Run'me*

Middleware*

OS*

Virtualiza'on*

Servers*

Storage*

Networking*

On#Premises#Yo

u*Manage*

Applica'on*

Data*

Run'me*

Middleware*

OS*

Virtualiza'on*

Servers*

Storage*

Networking*

IaaS$

You*Manage*

Vend

or*Provide

s*

Applica'on*

Data*

Run'me*

Middleware*

OS*

Virtualiza'on*

Servers*

Storage*

Networking*

PaaS$

You*Manage*

Vend

or*Provide

s*

Applica'on*

Data*

Run'me*

Middleware*

OS*

Virtualiza'on*

Servers*

Storage*

Networking*

SaaS#

Vend

or*Provide

s*

With PaaS, developer can focus just on building great apps. No need to worry about servers, operating system, loadbalancing, network or infrastructure.

Page 10: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Illustra(on  by  Rouge  Group  

PaaS

Page 11: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

– Yefim Natis, Gartner

“We believe PaaS will enable organizations become more agile and responsive”

“Organizations who are late, don't adopt PaaS will fall behind”

Page 12: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Modern Application Development

1. Mobile First Approach - Factoring applications into many apps.

2. Cloud-Backed - Adopting more abstract and machine-independent application models for back ends in the form of PaaS.

3. Agile Teams - Rapid iterations, frequent releases, integration of users

4. Continuously Integrated and Delivered - No downtimes

5. DevOps-Enabled - Developers own deployments

6. User Experience-Centric - Focusing on the design and appearance of the application

7. Service Oriented Architecture - Use of micro services to compose application

8. Lightweight - Less complex software that is less time-consuming to install, learn and use

9. Socially Oriented - UX patterns from social networks (timelines, event streams etc), Data is updated using event-based push-oriented patterns. Integrated search functionality.

10.API Factored and Surfaced - Componentize and granularize back-end software in order to achieve composable and easy-to-evolve back-end platforms.

Page 13: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Page 14: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Managed Application Runtime (MAR)

Scalable, Multi-language, Multi-database,

Application Platform as a Service

Page 15: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Supported Frameworks

Supported frameworks by 3rd party build packs

Scala, Clojure, Play, Gradle, Grails, PHP, Go, Meteorite, Perl, Dart, Nginx, Apache, Jekyll

Page 16: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Built-In Services

Page 17: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Add Ons

Enginio Data Storage (EDS)

Managed WebSocket (MWS)

Page 18: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Enginio Data Storage (EDS)

Flexible and powerful cloud data storage

with built-in user and data access control

Page 19: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Managed WebSocket (MWS)

Fully managed service implementing a bi-

directional, real-time communication gateway

for WebSockets.

Page 20: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Developer Friendly Deployment

Deploy using Git – the most common VCS among developers

>  git  push  qtc  master

Page 21: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Scalable Architecture

Red

isM

ongo

DB

Mon

goD

B

Your Application Built-­‐InServices

Applica2on  Instances End Users

Configure

Deploy

Scale With Your Business

Git

Push

API

Red

isM

ySQ

L

Envi

ronm

ent V

aria

bles

Load

Bal

ance

r

myawesome.com

Scaling

Page 22: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Web Console

Page 23: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Command Line Tool

Page 24: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

I Have an Idea

$$$

Page 25: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Mobile application that shows tweets in real

time

Page 26: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Back End

• DB where to store tweets

• Worker that retrieves/receives tweets from Twitter

• API that offers tweets to client app

• WebSocket server that push new tweets to client app

Page 27: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

• Enginio Data Storage

+ Schemaless

+ REST API

Database

Page 28: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

WebSocket Server• Managed WebSocket

+ Easy to start

+ REST API

Page 29: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Worker + API• Managed Application Runtime

+ PaaS

+ Just build the app

Page 30: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

1. get initial tweets

2. new tweet

3. save tweet

4. send WebSocket message

Page 31: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Worker - Rubyrequire  'tweetstream'  require  'qtc-­‐sdk'  !TweetStream.configure  do  |config|      config.consumer_key              =  ENV['CONSUMER_KEY']      config.consumer_secret        =  ENV['CONSUMER_SECRET']      config.oauth_token                =  ENV['OAUTH_TOKEN']      config.oauth_token_secret  =  ENV['OAUTH_SECRET']      config.auth_method                =  :oauth  end

eds  =  Qtc::Eds::Client.new(ENV['EDS_BACKEND_ID'])  mws  =  Qtc::Mws::Client.new(ENV['MWS_GATEWAY_ID'],  {access_token:  ENV['MWS_SECURITY_TOKEN']})  tweets  =  eds.collection('tweets')

daemon  =  TweetStream::Daemon.new('tracker',  :multiple  =>  true,  :no_pidfiles  =>  true)  daemon.track('#QtDD14')  do  |status|      if  !status.text.start_with?('RT  @')          tweet  =  {              created:  status.created_at,              tweet_id:  status.id,              text:  status.text,              name:  status.user.name,              screen_name:  status.user.screen_name,              profile_img_url:  status.user.profile_image_uri,              hashtags:  status.hashtags.map{|h|  h.text.downcase  }          }          tweets.insert(tweet)          mws.send_message(tweet.to_json,  {sockets:  nil,  tags:  ['QtDD14']})      end  end

Page 32: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

API - Ruby / Sinatrarequire  'sinatra'  require  'qtc-­‐sdk'  !set  :port,  ENV['PORT']

get  '/tweets/:hashtag'  do      eds  =  Qtc::Eds::Client.new(ENV['EDS_BACKEND_ID'])      tweets  =  eds.collection('tweets')      query  =  {          :q  =>  {          'hashtags'  =>  {'$in'  =>  [params[:hashtag]]              }          },          :limit  =>  50,          :sort  =>  [{"sortBy"  =>  "createdAt","direction"  =>  "desc"}]      }      content_type  :json,  'charset'  =>  'utf-­‐8'      result  =  tweets.find(query)      result.to_json  end

get  '/websocket_uri'  do      mws  =  Qtc::Mws::Client.new(ENV['MWS_GATEWAY_ID'],  {access_token:  ENV['MWS_SECURITY_TOKEN']})      socket  =  mws.create_socket(["QtDD14"])      content_type  :json,'charset'  =>  'utf-­‐8'      socket.to_json  end

Page 33: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Procfile

• When using most common frameworks, MAR can automatically detect the executable.

• You can explicitly declare what can be executed in a Procfile.

• Each line declares a process type - a command that can be executed from your built application

worker:  ruby  ./worker.rb  run  web:  rackup  -­‐p  $PORT  -­‐E  production

Page 34: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

> git push qtc master

Page 35: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

lanevala@it-­‐l-­‐m0015  ~/projects/qtdd-­‐twitter-­‐stream[master*]$  git  push  qtc  master  Counting  objects:  9,  done.  Delta  compression  using  up  to  8  threads.  Compressing  objects:  100%  (8/8),  done.  Writing  objects:  100%  (9/9),  1.46  KiB  |  0  bytes/s,  done.  Total  9  (delta  6),  reused  0  (delta  0)  -­‐-­‐-­‐-­‐-­‐>  Ruby  app  detected  -­‐-­‐-­‐-­‐-­‐>  Compiling  Ruby/Rack  -­‐-­‐-­‐-­‐-­‐>  Using  Ruby  version:  ruby-­‐2.1.2  -­‐-­‐-­‐-­‐-­‐>  Installing  dependencies  using  1.6.3                Running:  bundle  install  -­‐-­‐without  development:test  -­‐-­‐path  vendor/bundle  -­‐-­‐binstubs  vendor/bundle/bin  -­‐j4  -­‐-­‐deployment                Fetching  gem  metadata  from  https://rubygems.org/........                Using  eventmachine  1.0.3                Using  json  1.8.1                Using  thread_safe  0.3.4                Using  multi_json  1.10.1                Using  naught  1.0.0                Using  rack  1.5.2                Using  bundler  1.6.3                Using  em-­‐socksify  0.3.0                Using  http  0.6.1                Using  faraday  0.9.0                Using  em-­‐twitter  0.3.3                Installing  httpclient  2.5.2                Installing  inifile  3.0.0                Using  memoizable  0.4.2                Using  puma  2.9.1                Using  rails_12factor  0.0.3                Using  em-­‐http-­‐request  1.1.2                Using  twitter  5.11.0                Using  sinatra  1.4.5                Using  tweetstream  2.6.1                Installing  faye-­‐websocket  0.7.5                Using  qtc-­‐sdk  0.0.5  from  https://github.com/nevalla/qtc-­‐sdk-­‐ruby.git  (at  master)                Your  bundle  is  complete!                Gems  in  the  groups  development  and  test  were  not  installed.                It  was  installed  into  ./vendor/bundle                Bundle  completed  (9.04s)                Cleaning  up  the  bundler  cache.                Removing  httpclient  (2.4.0)                Removing  qtc-­‐sdk-­‐ruby  (8e7a9e3858e8)                  -­‐-­‐-­‐-­‐-­‐>  Discovering  process  types                Procfile  declares  types  -­‐>  worker,  web                Default  process  types  for  Ruby  -­‐>  rake,  console,  web  -­‐-­‐-­‐-­‐-­‐>  Compiled  slug  size  is  17M  -­‐-­‐-­‐-­‐-­‐>  Deploying  app                Uploading  app  container  ..  done.                mar-­‐eu-­‐1-­‐13viqrf8  deployed  to  http://mar-­‐eu-­‐1-­‐13viqrf8.qtcloudapp.com  To  git@git-­‐mar-­‐eu-­‐1.qtc.io:mar-­‐eu-­‐1-­‐13viqrf8        36e9190..b237ec8    master  -­‐>  master  lanevala@it-­‐l-­‐m0015  ~/projects/qtdd-­‐twitter-­‐stream[master*]$

Page 36: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Demo

Page 37: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Buildpacks

• When you deploy your Application, MAR slug compiler uses buildpack to prepares your code for execution.

• Each programming language and framework support is implemented as buildpack.

• Buildpack script will build the runtime environment on top of the Stack Image, a mini Linux distribution, and install everything that is needed.

Page 38: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

• Stack Image is a mini Linux distribution which defines the core operating system and runtime environment. MAR Stack Images are based on following Linux distributions:

• Lucid based on Ubuntu 10.04 LTS Lucid Lynx

• Trusty based on Ubuntu 14.04 LTS Trusty Tahr will be available soon!

Page 39: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

How to scale the application?

• MAR application processes can be scaled up or down dynamically.

• A typical web application has at least web process type declared in Procfile.

• You can set wanted concurrency level for process by issuing scale command using qtc-cli:

Page 40: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

$ qtc-cli mar scale web=2

$ qtc-cli mar scale worker=4

$ qtc-cli mar scale worker=0

Page 41: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Configuration Variables

• When developing server-side applications, it is very often required to have a configuration for application that is varying between environments. For example staging, production, testing, etc.

• Configuration to some external systems like database addresses, credentials or other environment variables might be required.

Page 42: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

• This configuration data is not included in your application code and can be changed independently.

• The configuration is exposed to a running application via environment variables.

• You can manage environment variables using the qtc-cli command line tool:

• qtc-cli mar envs:set SECRET_CODE=donotsharethis

Page 43: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Ports

Applicationinstances Load Balancer Client

ApplicationGET your-mar-address/index.html:80GET /index.html:47435

GET /index.html:47487

Page 44: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Logging

• Logs are a stream of time-ordered events aggregated from the output streams of all your application instance processes.

• MAR logger routes log streams from all these sources into single stream.

• Anything written to standard out (stdout) or standard error (stderr) is captured into application instance logs.

Page 45: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

• Qt/C++: qDebug() << "Log me to stdout”;

• QML & Node.js: console.log("Log me to stdout”);

• Ruby: puts "Log me to stdout”

!

• $ qtc-cli mar logs

Page 46: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Qt Backend

• Qt support is activated when application has one or more qmake project files in the root folder.

• If you set QMAKE_ARGS environment variable it will be passed to qmake command

• You must specify web process manually in Procfile:

• web: ./hello-world/server --port $PORT

Page 47: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Supported Qt Versions• New applications will default to the latest stable version of Qt (currently

5.3.2).

• You can specify any supported Qt runtime version to be used to run your application. This functionality is enabled when your project has .qt_runtime file.

• Available Qt runtimes:

• qt-5.3.0

• qt-5.3.1

• qt-5.3.2

• qt-5.4.0-beta

Page 48: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Page 49: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Further Actions

• Visit qtcloudservices.com

• Sign-up

• Use it

• Give us feedback

• Qt forum

[email protected]

Page 50: A Solid Back End for a Solid Qt Mobile Application€¦ · © 2013 The Qt Company A Solid Back End for a Solid Qt Mobile Application

© 2014 The Qt Company

Thank you!

http://www.qtcloudservices.com