EWD 3 Training Course Part 14: Using Ajax for QEWD Messages

R
Rob TweedIT Consultant, Developer & Director/Founder at M/Gateway Developments Ltd
Copyright © 2016 M/Gateway Developments Ltd
EWD 3 Training Course
Part 14
Using Ajax for QEWD messages
Rob Tweed
Director, M/Gateway Developments Ltd
Twitter: @rtweed
Copyright © 2016 M/Gateway Developments Ltd
Using Ajax for messages
• QEWD supports both WebSockets and
Ajax for message transport
• Ajax means message:
– Requests sent over HTTP
– Responses received as HTTP responses
• Why Ajax?
– Perhaps better scalability at very high end
– Well-understood protocol: some network
managers may be happier with it
Copyright © 2016 M/Gateway Developments Ltd
Using Ajax for messages
• Ajax / HTTP
– Messages can only be instigated by the client
– Back-end can't send messages to client except as a
response to a request
– A request must always return a response
• WebSockets
– Back-end can send messages to a client at any time,
without any initiating request
• No more polling
– "real-time" behaviour
– Growing evidence of it being a faster protocol
Copyright © 2016 M/Gateway Developments Ltd
How to use Ajax with QEWD
• Globally:
– Don't load socket.io into browser
– And/or remove io argument from EWD.start()
• Message-specific:
– Additional property for message object:
• ajax: true
• No change needed to back-end logic
• No need to restart back-end or workers
Copyright © 2016 M/Gateway Developments Ltd
Edit index.html
<html>
<head>
<title>Demo ewd-xpress application</title>
</head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/ewd-client.js"></script>
<script src="app.js"></script>
<button id="testBtn">Click Me</button>
<div id="content">
Content goes here
</div>
</body>
</html>
Copyright © 2016 M/Gateway Developments Ltd
Edit index.html
<html>
<head>
<title>Demo ewd-xpress application</title>
</head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="/ewd-client.js"></script>
<script src="app.js"></script>
<button id="testBtn">Click Me</button>
<div id="content">
Content goes here
</div>
</body>
</html>
Copyright © 2016 M/Gateway Developments Ltd
Edit app.js
$(document).ready(function() {
EWD.log = true;
EWD.on('ewd-registered', function() {
EWD.on('intermediate', function(responseObj) {
$('#content').text(responseObj.message.date);
});
EWD.on('socketDisconnected', function() {
$('#content').text('You have been logged out');
$('#testBtn').hide();
});
$('#testBtn').on('click', function(e) {
var message = {type: 'testButton'};
EWD.send(message, function(messageObj) {
$('#content').append('<br /> ' + messageObj.message.ok);
});
});
});
EWD.start('demo1', $);
});
Remove 3rd argment (io)
Copyright © 2016 M/Gateway Developments Ltd
Try it out
Copyright © 2016 M/Gateway Developments Ltd
Intermediate messages over Ajax
• HTTP mandates 1 response only per
request
• Back-end handler must use finished() for
the single response
– To ensure that the worker is released
• send() function is disabled and ignored
• Hence no intermediate messages in
browser console log
Copyright © 2016 M/Gateway Developments Ltd
Message-specific Ajax
• Can optionally specify particular messages
to use Ajax, even if WebSockets enabled
Copyright © 2016 M/Gateway Developments Ltd
Edit app.js
$(document).ready(function() {
EWD.log = true;
EWD.on('ewd-registered', function() {
EWD.on('intermediate', function(responseObj) {
$('#content').text(responseObj.message.date);
});
EWD.on('socketDisconnected', function() {
$('#content').text('You have been logged out');
$('#testBtn').hide();
});
$('#testBtn').on('click', function(e) {
var message = {type: 'testButton'};
EWD.send(message, function(messageObj) {
$('#content').append('<br /> ' + messageObj.message.ok);
});
EWD.send({
type: 'ajaxTestMsg',
ajax: true
}, function(responseObj) {
console.log('response via Ajax: ' + JSON.stringify(responseObj));
});
});
});
EWD.start('demo1', $);
});
Copyright © 2016 M/Gateway Developments Ltd
Try it out
Copyright © 2016 M/Gateway Developments Ltd
Add back-end handler
• C:ewd3node_modulesdemo1.js
module.exports = {
handlers: {
testButton: function(messageObj, session, send, finished) {
session.data.$('foo').value = 'bar';
send({
type: 'intermediate',
foo: 'bar',
date: new Date().toString()
});
finished({
ok: 'testButton message was processed successfully!'
});
},
ajaxTestMsg: function(messageObj, session, send, finished) {
console.log('ajax message processed');
finished({
ok: 'ajax message processed successfully'
});
}
}
};
Standard handler pattern
But can't use send()
Copyright © 2016 M/Gateway Developments Ltd
Try it out
Copyright © 2016 M/Gateway Developments Ltd
Ajax Dependencies
• The built-in behaviour described here
relies on jQuery being loaded into the
browser
• jQuery isn't essential when using QEWD
– It's a default, but not mandatory, dependency
• If your preferred framework provides its
own Ajax interface function, this can be
integrated instead
Copyright © 2016 M/Gateway Developments Ltd
EWD.start()
EWD.start(appName, $, io, customAjaxFn,url)
appName = name of application for registration
$ = jQuery object (if being used)
io = socket.io object (if using WebSockets)
customAjaxFn = alternative Ajax handler function (if you want to
use a different framework from jQuery)
url = for use with non-browser clients, eg when using
React Native
Copyright © 2016 M/Gateway Developments Ltd
EWD.start()
EWD.start({
application: appName,
$: $,
io: io,
ajax: function(params, success, failure) {… },
url: url
});
Cleaner to use an object argument instead of
specifying multiple arguments by position
If not relevant, don't define them in the object
Copyright © 2016 M/Gateway Developments Ltd
EWD.start() with custom Ajax
EWD.start({
application: 'extJSDemo',
ajax: function(params, success, failure) {
console.log('sending message using custom Ajax function for ExtJS');
// ewd-client's ajax wrapper function provides the information you'll need in a params object, so here we re-map them for extJS
Ext.Ajax.request({
url: params.url,
method: params.type.toUpperCase(),
timeout: params.timeout,
jsonData: params.data,
success: function(response, opts) {
// similarly we invoke ewd-client's success function after mapping the extJS data
var data = Ext.decode(response.responseText);
success(data);
},
failure: function(response, opts) {
// and here we invoke ewd-client's failure function, after re-formatting the extJS failure text
console.log('Ajax server-side failure with status code ' + response.status);
failure(response.responseText);
}
});
}
});
1 of 18

Recommended

EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 2 by
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 2EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 2
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 2Rob Tweed
597 views56 slides
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4 by
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4Rob Tweed
718 views31 slides
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap... by
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...Rob Tweed
932 views45 slides
EWD 3 Training Course Part 20: The DocumentNode Object by
EWD 3 Training Course Part 20: The DocumentNode ObjectEWD 3 Training Course Part 20: The DocumentNode Object
EWD 3 Training Course Part 20: The DocumentNode ObjectRob Tweed
1K views41 slides
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ... by
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...Rob Tweed
805 views14 slides
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5 by
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5Rob Tweed
621 views73 slides

More Related Content

What's hot

EWD 3 Training Course Part 5b: First Steps in Building a QEWD Application by
EWD 3 Training Course Part 5b: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5b: First Steps in Building a QEWD ApplicationRob Tweed
999 views33 slides
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3 by
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3Rob Tweed
627 views19 slides
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services by
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST ServicesEWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST ServicesRob Tweed
891 views93 slides
EWD 3 Training Course Part 2: EWD 3 Overview by
EWD 3 Training Course Part 2: EWD 3 OverviewEWD 3 Training Course Part 2: EWD 3 Overview
EWD 3 Training Course Part 2: EWD 3 OverviewRob Tweed
2.1K views93 slides
EWD 3 Training Course Part 4: Installing & Configuring QEWD by
EWD 3 Training Course Part 4: Installing & Configuring QEWDEWD 3 Training Course Part 4: Installing & Configuring QEWD
EWD 3 Training Course Part 4: Installing & Configuring QEWDRob Tweed
2.9K views31 slides
EWD 3 Training Course Part 11: Handling Errors in QEWD by
EWD 3 Training Course Part 11: Handling Errors in QEWDEWD 3 Training Course Part 11: Handling Errors in QEWD
EWD 3 Training Course Part 11: Handling Errors in QEWDRob Tweed
639 views12 slides

What's hot(20)

EWD 3 Training Course Part 5b: First Steps in Building a QEWD Application by Rob Tweed
EWD 3 Training Course Part 5b: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
Rob Tweed999 views
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3 by Rob Tweed
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
Rob Tweed627 views
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services by Rob Tweed
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST ServicesEWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
Rob Tweed891 views
EWD 3 Training Course Part 2: EWD 3 Overview by Rob Tweed
EWD 3 Training Course Part 2: EWD 3 OverviewEWD 3 Training Course Part 2: EWD 3 Overview
EWD 3 Training Course Part 2: EWD 3 Overview
Rob Tweed2.1K views
EWD 3 Training Course Part 4: Installing & Configuring QEWD by Rob Tweed
EWD 3 Training Course Part 4: Installing & Configuring QEWDEWD 3 Training Course Part 4: Installing & Configuring QEWD
EWD 3 Training Course Part 4: Installing & Configuring QEWD
Rob Tweed2.9K views
EWD 3 Training Course Part 11: Handling Errors in QEWD by Rob Tweed
EWD 3 Training Course Part 11: Handling Errors in QEWDEWD 3 Training Course Part 11: Handling Errors in QEWD
EWD 3 Training Course Part 11: Handling Errors in QEWD
Rob Tweed639 views
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application by Rob Tweed
EWD 3 Training Course Part 5a: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
Rob Tweed1.4K views
EWD 3 Training Course Part 7: Applying the QEWD Messaging Pattern by Rob Tweed
EWD 3 Training Course Part 7: Applying the QEWD Messaging PatternEWD 3 Training Course Part 7: Applying the QEWD Messaging Pattern
EWD 3 Training Course Part 7: Applying the QEWD Messaging Pattern
Rob Tweed1.3K views
QEWD.js, JSON Web Tokens & MicroServices by Rob Tweed
QEWD.js, JSON Web Tokens & MicroServicesQEWD.js, JSON Web Tokens & MicroServices
QEWD.js, JSON Web Tokens & MicroServices
Rob Tweed903 views
EWD 3 Training Course Part 27: The QEWD Session by Rob Tweed
EWD 3 Training Course Part 27: The QEWD SessionEWD 3 Training Course Part 27: The QEWD Session
EWD 3 Training Course Part 27: The QEWD Session
Rob Tweed920 views
EWD 3 Training Course Part 30: Modularising QEWD Applications by Rob Tweed
EWD 3 Training Course Part 30: Modularising QEWD ApplicationsEWD 3 Training Course Part 30: Modularising QEWD Applications
EWD 3 Training Course Part 30: Modularising QEWD Applications
Rob Tweed1.1K views
EWD 3 Training Course Part 28: Integrating Legacy Mumps Code with QEWD by Rob Tweed
EWD 3 Training Course Part 28: Integrating Legacy Mumps Code with QEWDEWD 3 Training Course Part 28: Integrating Legacy Mumps Code with QEWD
EWD 3 Training Course Part 28: Integrating Legacy Mumps Code with QEWD
Rob Tweed1.2K views
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data... by Rob Tweed
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...
Rob Tweed3.9K views
EWD 3 Training Course Part 10: QEWD Sessions and User Authentication by Rob Tweed
EWD 3 Training Course Part 10: QEWD Sessions and User AuthenticationEWD 3 Training Course Part 10: QEWD Sessions and User Authentication
EWD 3 Training Course Part 10: QEWD Sessions and User Authentication
Rob Tweed999 views
EWD 3 Training Course Part 8: Anatomy of the QEWD Messaging Cycle by Rob Tweed
EWD 3 Training Course Part 8: Anatomy of the QEWD Messaging CycleEWD 3 Training Course Part 8: Anatomy of the QEWD Messaging Cycle
EWD 3 Training Course Part 8: Anatomy of the QEWD Messaging Cycle
Rob Tweed720 views
EWD 3 Training Course Part 19: The cache.node APIs by Rob Tweed
EWD 3 Training Course Part 19: The cache.node APIsEWD 3 Training Course Part 19: The cache.node APIs
EWD 3 Training Course Part 19: The cache.node APIs
Rob Tweed905 views
qewd-ripple: The Ripple OSI Middle Tier by Rob Tweed
qewd-ripple: The Ripple OSI Middle Tierqewd-ripple: The Ripple OSI Middle Tier
qewd-ripple: The Ripple OSI Middle Tier
Rob Tweed720 views
EWD 3 Training Course Part 29: Running QEWD as a Service by Rob Tweed
EWD 3 Training Course Part 29: Running QEWD as a ServiceEWD 3 Training Course Part 29: Running QEWD as a Service
EWD 3 Training Course Part 29: Running QEWD as a Service
Rob Tweed1K views
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services by Rob Tweed
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Servicesewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services
Rob Tweed333 views
Composable and streamable Play apps by Yevgeniy Brikman
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
Yevgeniy Brikman122.3K views

Similar to EWD 3 Training Course Part 14: Using Ajax for QEWD Messages

125 고성능 web view-deview 2013 발표 자료_공유용 by
125 고성능 web view-deview 2013 발표 자료_공유용125 고성능 web view-deview 2013 발표 자료_공유용
125 고성능 web view-deview 2013 발표 자료_공유용NAVER D2
30.4K views37 slides
Practical AngularJS by
Practical AngularJSPractical AngularJS
Practical AngularJSWei Ru
1.2K views47 slides
Gdg dev fest hybrid apps your own mini-cordova by
Gdg dev fest hybrid apps  your own mini-cordovaGdg dev fest hybrid apps  your own mini-cordova
Gdg dev fest hybrid apps your own mini-cordovaAyman Mahfouz
331 views28 slides
Love at first Vue by
Love at first VueLove at first Vue
Love at first VueDalibor Gogic
660 views37 slides
Spring Web Services: SOAP vs. REST by
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
22.4K views42 slides

Similar to EWD 3 Training Course Part 14: Using Ajax for QEWD Messages(20)

125 고성능 web view-deview 2013 발표 자료_공유용 by NAVER D2
125 고성능 web view-deview 2013 발표 자료_공유용125 고성능 web view-deview 2013 발표 자료_공유용
125 고성능 web view-deview 2013 발표 자료_공유용
NAVER D230.4K views
Practical AngularJS by Wei Ru
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru1.2K views
Gdg dev fest hybrid apps your own mini-cordova by Ayman Mahfouz
Gdg dev fest hybrid apps  your own mini-cordovaGdg dev fest hybrid apps  your own mini-cordova
Gdg dev fest hybrid apps your own mini-cordova
Ayman Mahfouz331 views
Spring Web Services: SOAP vs. REST by Sam Brannen
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
Sam Brannen22.4K views
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5) by Igor Bronovskyy
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy410 views
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres... by Rob Tweed
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
Rob Tweed1.1K views
Quick and Easy Development with Node.js and Couchbase Server by Nic Raboy
Quick and Easy Development with Node.js and Couchbase ServerQuick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase Server
Nic Raboy756 views
Event-driven IO server-side JavaScript environment based on V8 Engine by Ricardo Silva
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva4.1K views
WSO2Con Asia 2014 - WSO2 AppDev Platform for the Connected Business by WSO2
WSO2Con Asia 2014 - WSO2 AppDev Platform for the Connected BusinessWSO2Con Asia 2014 - WSO2 AppDev Platform for the Connected Business
WSO2Con Asia 2014 - WSO2 AppDev Platform for the Connected Business
WSO21.2K views
From Web App Model Design to Production with Wakanda by Alexandre Morgaut
From Web App Model Design to Production with WakandaFrom Web App Model Design to Production with Wakanda
From Web App Model Design to Production with Wakanda
Alexandre Morgaut2.5K views
Getting started with Websocket and Server-sent Events using Java - Arun Gupta by jaxconf
Getting started with Websocket and Server-sent Events using Java - Arun Gupta Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
jaxconf583 views
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta by Codemotion
Getting Started with WebSocket and Server-Sent Events using Java by Arun GuptaGetting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Codemotion1.6K views
soft-shake.ch - Hands on Node.js by soft-shake.ch
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
soft-shake.ch2.3K views
Java Web Programming on Google Cloud Platform [1/3] : Google App Engine by IMC Institute
Java Web Programming on Google Cloud Platform [1/3] : Google App EngineJava Web Programming on Google Cloud Platform [1/3] : Google App Engine
Java Web Programming on Google Cloud Platform [1/3] : Google App Engine
IMC Institute2.9K views

More from Rob Tweed

QEWD Update by
QEWD UpdateQEWD Update
QEWD UpdateRob Tweed
945 views32 slides
Data Persistence as a Language Feature by
Data Persistence as a Language FeatureData Persistence as a Language Feature
Data Persistence as a Language FeatureRob Tweed
1.3K views108 slides
LNUG: Having Your Node.js Cake and Eating It Too by
LNUG: Having Your Node.js Cake and Eating It TooLNUG: Having Your Node.js Cake and Eating It Too
LNUG: Having Your Node.js Cake and Eating It TooRob Tweed
2.8K views81 slides
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService Functionality by
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService FunctionalityEWD 3 Training Course Part 45: Using QEWD's Advanced MicroService Functionality
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService FunctionalityRob Tweed
2.1K views254 slides
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.js by
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.jsEWD 3 Training Course Part 44: Creating MicroServices with QEWD.js
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.jsRob Tweed
1.5K views136 slides
QEWD.js: Have your Node.js Cake and Eat It Too by
QEWD.js: Have your Node.js Cake and Eat It TooQEWD.js: Have your Node.js Cake and Eat It Too
QEWD.js: Have your Node.js Cake and Eat It TooRob Tweed
628 views76 slides

More from Rob Tweed(15)

QEWD Update by Rob Tweed
QEWD UpdateQEWD Update
QEWD Update
Rob Tweed945 views
Data Persistence as a Language Feature by Rob Tweed
Data Persistence as a Language FeatureData Persistence as a Language Feature
Data Persistence as a Language Feature
Rob Tweed1.3K views
LNUG: Having Your Node.js Cake and Eating It Too by Rob Tweed
LNUG: Having Your Node.js Cake and Eating It TooLNUG: Having Your Node.js Cake and Eating It Too
LNUG: Having Your Node.js Cake and Eating It Too
Rob Tweed2.8K views
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService Functionality by Rob Tweed
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService FunctionalityEWD 3 Training Course Part 45: Using QEWD's Advanced MicroService Functionality
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService Functionality
Rob Tweed2.1K views
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.js by Rob Tweed
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.jsEWD 3 Training Course Part 44: Creating MicroServices with QEWD.js
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.js
Rob Tweed1.5K views
QEWD.js: Have your Node.js Cake and Eat It Too by Rob Tweed
QEWD.js: Have your Node.js Cake and Eat It TooQEWD.js: Have your Node.js Cake and Eat It Too
QEWD.js: Have your Node.js Cake and Eat It Too
Rob Tweed628 views
EWD 3 Training Course Part 42: The QEWD Docker Appliance by Rob Tweed
EWD 3 Training Course Part 42: The QEWD Docker ApplianceEWD 3 Training Course Part 42: The QEWD Docker Appliance
EWD 3 Training Course Part 42: The QEWD Docker Appliance
Rob Tweed1.3K views
EWD 3 Training Course Part 35: QEWD Session Locking by Rob Tweed
EWD 3 Training Course Part 35: QEWD Session LockingEWD 3 Training Course Part 35: QEWD Session Locking
EWD 3 Training Course Part 35: QEWD Session Locking
Rob Tweed532 views
EWD 3 Training Course Part 34: QEWD Resilient Mode by Rob Tweed
EWD 3 Training Course Part 34: QEWD Resilient ModeEWD 3 Training Course Part 34: QEWD Resilient Mode
EWD 3 Training Course Part 34: QEWD Resilient Mode
Rob Tweed750 views
EWD 3 Training Course Part 33: Configuring QEWD to use CORS by Rob Tweed
EWD 3 Training Course Part 33: Configuring QEWD to use CORSEWD 3 Training Course Part 33: Configuring QEWD to use CORS
EWD 3 Training Course Part 33: Configuring QEWD to use CORS
Rob Tweed1.1K views
EWD 3 Training Course Part 32: Configuring QEWD to use SSL/HTTPS by Rob Tweed
EWD 3 Training Course Part 32: Configuring QEWD to use SSL/HTTPSEWD 3 Training Course Part 32: Configuring QEWD to use SSL/HTTPS
EWD 3 Training Course Part 32: Configuring QEWD to use SSL/HTTPS
Rob Tweed608 views
EWD 3 Training Course Part 31: Using QEWD for Web and REST Services by Rob Tweed
EWD 3 Training Course Part 31: Using QEWD for Web and REST ServicesEWD 3 Training Course Part 31: Using QEWD for Web and REST Services
EWD 3 Training Course Part 31: Using QEWD for Web and REST Services
Rob Tweed3.3K views
EWD 3 Training Course Part 26: Event-driven Indexing by Rob Tweed
EWD 3 Training Course Part 26: Event-driven IndexingEWD 3 Training Course Part 26: Event-driven Indexing
EWD 3 Training Course Part 26: Event-driven Indexing
Rob Tweed678 views
EWD 3 Training Course Part 25: Document Database Capabilities by Rob Tweed
EWD 3 Training Course Part 25: Document Database CapabilitiesEWD 3 Training Course Part 25: Document Database Capabilities
EWD 3 Training Course Part 25: Document Database Capabilities
Rob Tweed905 views
EWD 3 Training Course Part 24: Traversing a Document's Leaf Nodes by Rob Tweed
EWD 3 Training Course Part 24: Traversing a Document's Leaf NodesEWD 3 Training Course Part 24: Traversing a Document's Leaf Nodes
EWD 3 Training Course Part 24: Traversing a Document's Leaf Nodes
Rob Tweed622 views

Recently uploaded

Fleet Management Software in India by
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India Fleetable
11 views1 slide
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...Deltares
11 views23 slides
HarshithAkkapelli_Presentation.pdf by
HarshithAkkapelli_Presentation.pdfHarshithAkkapelli_Presentation.pdf
HarshithAkkapelli_Presentation.pdfharshithakkapelli
11 views16 slides
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit... by
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...Deltares
13 views34 slides
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... by
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...Marc Müller
38 views62 slides
SAP FOR CONTRACT MANUFACTURING.pdf by
SAP FOR CONTRACT MANUFACTURING.pdfSAP FOR CONTRACT MANUFACTURING.pdf
SAP FOR CONTRACT MANUFACTURING.pdfVirendra Rai, PMP
11 views2 slides

Recently uploaded(20)

Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares11 views
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit... by Deltares
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
Deltares13 views
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... by Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller38 views
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon by Deltares
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
Deltares13 views
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida by Deltares
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - PridaDSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
Deltares18 views
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ... by marksimpsongw
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...
marksimpsongw76 views
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 views
DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)... by Deltares
DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)...DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)...
DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)...
Deltares9 views
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by Ra'Fat Al-Msie'deen
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
Deltares17 views
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm13 views
Roadmap y Novedades de producto by Neo4j
Roadmap y Novedades de productoRoadmap y Novedades de producto
Roadmap y Novedades de producto
Neo4j50 views
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares9 views
A first look at MariaDB 11.x features and ideas on how to use them by Federico Razzoli
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use them
Federico Razzoli45 views
Consulting for Data Monetization Maximizing the Profit Potential of Your Data... by Flexsin
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Flexsin 15 views
Upgrading Incident Management with Icinga - Icinga Camp Milan 2023 by Icinga
Upgrading Incident Management with Icinga - Icinga Camp Milan 2023Upgrading Incident Management with Icinga - Icinga Camp Milan 2023
Upgrading Incident Management with Icinga - Icinga Camp Milan 2023
Icinga38 views

EWD 3 Training Course Part 14: Using Ajax for QEWD Messages

  • 1. Copyright © 2016 M/Gateway Developments Ltd EWD 3 Training Course Part 14 Using Ajax for QEWD messages Rob Tweed Director, M/Gateway Developments Ltd Twitter: @rtweed
  • 2. Copyright © 2016 M/Gateway Developments Ltd Using Ajax for messages • QEWD supports both WebSockets and Ajax for message transport • Ajax means message: – Requests sent over HTTP – Responses received as HTTP responses • Why Ajax? – Perhaps better scalability at very high end – Well-understood protocol: some network managers may be happier with it
  • 3. Copyright © 2016 M/Gateway Developments Ltd Using Ajax for messages • Ajax / HTTP – Messages can only be instigated by the client – Back-end can't send messages to client except as a response to a request – A request must always return a response • WebSockets – Back-end can send messages to a client at any time, without any initiating request • No more polling – "real-time" behaviour – Growing evidence of it being a faster protocol
  • 4. Copyright © 2016 M/Gateway Developments Ltd How to use Ajax with QEWD • Globally: – Don't load socket.io into browser – And/or remove io argument from EWD.start() • Message-specific: – Additional property for message object: • ajax: true • No change needed to back-end logic • No need to restart back-end or workers
  • 5. Copyright © 2016 M/Gateway Developments Ltd Edit index.html <html> <head> <title>Demo ewd-xpress application</title> </head> <body> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <script src="/socket.io/socket.io.js"></script> <script src="/ewd-client.js"></script> <script src="app.js"></script> <button id="testBtn">Click Me</button> <div id="content"> Content goes here </div> </body> </html>
  • 6. Copyright © 2016 M/Gateway Developments Ltd Edit index.html <html> <head> <title>Demo ewd-xpress application</title> </head> <body> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <script src="/ewd-client.js"></script> <script src="app.js"></script> <button id="testBtn">Click Me</button> <div id="content"> Content goes here </div> </body> </html>
  • 7. Copyright © 2016 M/Gateway Developments Ltd Edit app.js $(document).ready(function() { EWD.log = true; EWD.on('ewd-registered', function() { EWD.on('intermediate', function(responseObj) { $('#content').text(responseObj.message.date); }); EWD.on('socketDisconnected', function() { $('#content').text('You have been logged out'); $('#testBtn').hide(); }); $('#testBtn').on('click', function(e) { var message = {type: 'testButton'}; EWD.send(message, function(messageObj) { $('#content').append('<br /> ' + messageObj.message.ok); }); }); }); EWD.start('demo1', $); }); Remove 3rd argment (io)
  • 8. Copyright © 2016 M/Gateway Developments Ltd Try it out
  • 9. Copyright © 2016 M/Gateway Developments Ltd Intermediate messages over Ajax • HTTP mandates 1 response only per request • Back-end handler must use finished() for the single response – To ensure that the worker is released • send() function is disabled and ignored • Hence no intermediate messages in browser console log
  • 10. Copyright © 2016 M/Gateway Developments Ltd Message-specific Ajax • Can optionally specify particular messages to use Ajax, even if WebSockets enabled
  • 11. Copyright © 2016 M/Gateway Developments Ltd Edit app.js $(document).ready(function() { EWD.log = true; EWD.on('ewd-registered', function() { EWD.on('intermediate', function(responseObj) { $('#content').text(responseObj.message.date); }); EWD.on('socketDisconnected', function() { $('#content').text('You have been logged out'); $('#testBtn').hide(); }); $('#testBtn').on('click', function(e) { var message = {type: 'testButton'}; EWD.send(message, function(messageObj) { $('#content').append('<br /> ' + messageObj.message.ok); }); EWD.send({ type: 'ajaxTestMsg', ajax: true }, function(responseObj) { console.log('response via Ajax: ' + JSON.stringify(responseObj)); }); }); }); EWD.start('demo1', $); });
  • 12. Copyright © 2016 M/Gateway Developments Ltd Try it out
  • 13. Copyright © 2016 M/Gateway Developments Ltd Add back-end handler • C:ewd3node_modulesdemo1.js module.exports = { handlers: { testButton: function(messageObj, session, send, finished) { session.data.$('foo').value = 'bar'; send({ type: 'intermediate', foo: 'bar', date: new Date().toString() }); finished({ ok: 'testButton message was processed successfully!' }); }, ajaxTestMsg: function(messageObj, session, send, finished) { console.log('ajax message processed'); finished({ ok: 'ajax message processed successfully' }); } } }; Standard handler pattern But can't use send()
  • 14. Copyright © 2016 M/Gateway Developments Ltd Try it out
  • 15. Copyright © 2016 M/Gateway Developments Ltd Ajax Dependencies • The built-in behaviour described here relies on jQuery being loaded into the browser • jQuery isn't essential when using QEWD – It's a default, but not mandatory, dependency • If your preferred framework provides its own Ajax interface function, this can be integrated instead
  • 16. Copyright © 2016 M/Gateway Developments Ltd EWD.start() EWD.start(appName, $, io, customAjaxFn,url) appName = name of application for registration $ = jQuery object (if being used) io = socket.io object (if using WebSockets) customAjaxFn = alternative Ajax handler function (if you want to use a different framework from jQuery) url = for use with non-browser clients, eg when using React Native
  • 17. Copyright © 2016 M/Gateway Developments Ltd EWD.start() EWD.start({ application: appName, $: $, io: io, ajax: function(params, success, failure) {… }, url: url }); Cleaner to use an object argument instead of specifying multiple arguments by position If not relevant, don't define them in the object
  • 18. Copyright © 2016 M/Gateway Developments Ltd EWD.start() with custom Ajax EWD.start({ application: 'extJSDemo', ajax: function(params, success, failure) { console.log('sending message using custom Ajax function for ExtJS'); // ewd-client's ajax wrapper function provides the information you'll need in a params object, so here we re-map them for extJS Ext.Ajax.request({ url: params.url, method: params.type.toUpperCase(), timeout: params.timeout, jsonData: params.data, success: function(response, opts) { // similarly we invoke ewd-client's success function after mapping the extJS data var data = Ext.decode(response.responseText); success(data); }, failure: function(response, opts) { // and here we invoke ewd-client's failure function, after re-formatting the extJS failure text console.log('Ajax server-side failure with status code ' + response.status); failure(response.responseText); } }); } });