Chintana Wilamuna
Solutions Architect
April, 06 2017
A programming language for the networked world
Asanka Abeysinghe
Vice President, Solutions Architecture
Future of Enterprise Integration Meetup: Silicon Valley
The world is changing …
• Networked interactions are no longer a niche
– The new shared library
– Ability to reuse and recompose is key to agility
– Everything you write integrates with other things
• Configuration over code not workable at scale
• Containers, microservices, micro integrations
Centralized vs decentralized
System
Ɣ
System
Ɣ
Service
Foo
Centralized Integration Solution
Service
Bar
System
α
System
β
Service
Foo
Integration
Microservice unit
Service
Bar
System
α
System
β
Integration Microservice unitVs
From data flows to sequence diagrams
• Every ESB technology based on dataflow
• Not very good at describing complex multi-party
interactions that are now common
• Sequence diagrams to the rescue
– Perfect for describing parallel, coordinated activities of many
parties
Timeline
2005
Apache Synapse
2008 Carbon
OSGified
Aug-2016 NEL
Q4-2016
Ballerina:
language spec
Apr-2017
0.85
Feb-2017
0.8 tec.preview
Why stop at using sequence diagrams to describe
programs?
Ballerina
• General purpose programming language, but optimized for
integration
• Strongly typed, concurrent with both text and graphical
syntaxes
• Modern, network-aware, data-aware, security-aware
programming system inspired by Java, Go, Maven, ...
The Ballerina Language
• Graphical/textual parity with ability to switch back and forth
• Common integration capabilities are baked into the language:
– Deep HTTP/REST/Swagger alignment
– Connectors for Web APIs and non-HTTP APIs
– Support for JSON, XML, (No)SQL data and mapping
• No magic – no weird syntax exceptions, everything is derived
from a few key language concepts
• Maximize developer productivity and abstraction clarity
• Support high performance implementations: low latency, low
memory and fast startup
Hello, World!
import ballerina.lang.system;
function main(string[] args) {
system:println("Hello, World!");
}
Demo: hello world
Ballerina knows services (and main)!
• Two models of programming: service and main
• Services are network invoked collections of entry points
• Main is regular main()
Demo: simple service
Ballerina knows data!
• XML, JSON and datatable are built-in data types
• All streamed, high performant
• Data (type) mapping between Ballerina types, XML, JSON and
datatables
Ballerina knows network APIs!
• Client and server connectors for HTTP 1.1/2, WebSockets, JMS,
(S)FTP(S) and more
• Client connectors for BasicAuth, OAuth, AmazonAuth, SOAP
• Client connectors for Web APIs: Twitter, GMail, LinkedIn,
Facebook, Lambda Functions, …
Ballerina knows (or rather, is) Swagger!
• Ballerina programs’ interface (in HTTP case) is
expressed in Swagger
– Text syntax, graphical syntax and Swagger syntax
are interchangeable
• Edit interface anywhere
• No more standard limitations of interface first design
Ballerina knows Docker!
• Built in build command to create Docker image with executable
Ballerina program package
• Run on any container management platform
Ballerina is highly extensible!
• Code organized into packages like Go
• Repository model similar to Maven/NPM/Go giving ability to
create ecosystem of connector contributors
• Recomposable network connectors
Ballerina is open source!
• Patent pending technology
• Implementation released under Apache License v2.0
– Fork me on GitHub: https://github.com/ballerinalang/
• Community
– Users: ballerina-user@googlegroups.com
– Slack: #ballerinalang
– Twitter: @ballerinalang
– StackOverflow: #ballerinalang
– Developers: ballerina-dev@googlegroups.com
Language Walk-Through
https://github.com/ballerinalang/ballerina/blob/master/docs/specification/README.
md
Ballerina Concepts
• Functions
• Services
• Resources
• Connectors
• Actions
• Workers
Modularity: Files & Packages
• Package model inspired by Go
– package org.wso2.foo;
• Packages are defined by the set of all files in a directory
• All symbols exposed by any file in the package is referred to with
packagename:symbolname
– In other words, file names have no meaning in the namespace of the language
• To use symbols from a package you must import:
– import org.wso2.foo [as xx];
• Packages that start with ballerina.* and ballerinax.* are reserved
• Packages will be versioned - details later
Type System
ANY
VALUE TYPE
INT
FLOAT
BOOLEAN
REFERENCE TYPE
BUILT-IN USER DEFINED
STRUCT ARRAY
STRING
MAP
EXCEPTION
MESSAGE
XML
JSON
ITERATOR
XMLDOCUMENT
DATATABLE
JSON Support
• Variables of type “json” can hold any JSON value
• Optionally, can associate a JSON Schema to the
declaration:
– json[<json_schema_name>] jsdoc;
– Constraints the value to conform to the schema
• Useful for type mapping
• JSON literals can be used to initialize JSON typed variables
– json address_json = `{"name" : "$name", "streetName" : "${street}"}`;
XML Support
• Variables of type “xml” can hold any XML element
• Variables of type “xmldocument” can hold any XML
document
• Optionally can associate an XML Schema to constrain the
value space of XML
– xml[<{xsd_namespace_name}type_name}>] e;
• XML literals
– xmlElement address_xml = `<address><name>${name}</name></address>`;
Tabular Data Support
• Variables of type “datatable” can hold any tabular data
coming from a data source
• Database connectors to query and produce datatables
Type Coercion and Conversion
• Lossless type coercions are automatic
– E.g. int -> float
• Other type conversions can be invoked with the cast
operator
– TypeT1 v1;
– TypeT2 v2;
– v2 = (TypeT2) v1;
• Users can define their own type mappers which fit into the
language type system and get invoked with the cast
operator
Type Mappers
typemapper TypeMapperName (TypeName VariableName) (TypeName) {
Statement;+
}
(More constraints coming)
Language Statements
• assignment
• if
• while
• break
• try/catch/throw
• return
• action invocation
• fork/join
• worker initiation/invocation/join/reply
Fork/Join
fork (MessageName) {
worker WorkerName (message VariableName) {
Statement;+
[reply MessageName;]
}+
} [join (JoinCondition) (message[] VariableName) {
Statement;*
} timeout (Expression) (message[] VariableName) {
Statement;*
}]
Fork/Join
Worker Interaction
worker WorkerName (message m) {
Statement;+
[reply MessageName;]
}
• Send/receive message to coordinate
MessageName -> WorkerName;
MessageName <- WorkerName;
Language System
Ballerina is not just the language
• Composer with debugging, type mapping
• IDE plugins
• Docerina
• Testerina
• (Coming soon) Packerina
Composer
• Textual, graphical and Swagger editing of Ballerina
programs
• Runs in the browser
– Currently not packaged with embedded Chromium;
considering it
• Will be hosted in the cloud as well
IDE Plugins
• Available (still WIP)
– Atom
– Vim
– Idea
– Sublime Text
– VSCode
– Adobe Brackets
• More to be done!
– Send a pull request ☺
Docerina
• Tool to generate API docs for your Ballerina code
• All Ballerina code is documented using Docerina
Testerina
• Unit test and mocking framework for Ballerina
Packerina
• Tool to manage repositories, manage dependencies and
build Ballerina programs
• Coming soon under this name .. partly shipping already
Ballerina Future
When should I use Ballerina?
• Write integration microservices
– 80-20 rule: if 80% of your service is about integrating with
other services, data and APIs then use Ballerina. If its just
20% then use Java / Node / Go / XYZ
• Re-compose existing services to be API backends
• Write integration scripts
– Replacement for shell scripts that use curl too much
Integration Microservice in MSA
Summary
Available now: Ballerina v0.85 Technology
Preview
• Language runtime
– Run once, run one service, run many services (bus)
• Developer tools
– Composer: browser based graphic/text/Swagger editor and
debugger
– IDE plugins: Idea, Atom, Vim, Sublime, VSCode, Brackets
– Testerina: Unit testing framework
– Docerina: API doc generation framework
• Connectors
http://ballerinalang.org/
Next Steps
• Download, twirl with it, give us feedback
• Engage with the community
– Users: ballerina-user@googlegroups.com
– Slack: #ballerinalang
– Twitter: @ballerinalang
– StackOverflow: #ballerinalang
– Developers: ballerina-dev@googlegroups.com
Demo: advanced use-cases
Questions?
Ballerina Concepts: Functions
Ballerina Concepts: Resource
Ballerina Concepts: Services
Ballerina Concepts: Client & Server Connectors
• Ballerina services are attached to network protocols with
server connectors
• Ballerina programs interact with network endpoints with
client connectors
– Networked endpoints can mean pretty much anything
WORKERCLIENT
CLIENT WORKER
CONNECTOR
CONNECTOR
CONNECTOR
CONNECTOR
START
REPLY
STATEMENT
ACTION
WORKER2
WORKER2

Ballerina- A programming language for the networked world

  • 1.
    Chintana Wilamuna Solutions Architect April,06 2017 A programming language for the networked world Asanka Abeysinghe Vice President, Solutions Architecture Future of Enterprise Integration Meetup: Silicon Valley
  • 2.
    The world ischanging … • Networked interactions are no longer a niche – The new shared library – Ability to reuse and recompose is key to agility – Everything you write integrates with other things • Configuration over code not workable at scale • Containers, microservices, micro integrations
  • 3.
    Centralized vs decentralized System Ɣ System Ɣ Service Foo CentralizedIntegration Solution Service Bar System α System β Service Foo Integration Microservice unit Service Bar System α System β Integration Microservice unitVs
  • 4.
    From data flowsto sequence diagrams • Every ESB technology based on dataflow • Not very good at describing complex multi-party interactions that are now common • Sequence diagrams to the rescue – Perfect for describing parallel, coordinated activities of many parties
  • 5.
    Timeline 2005 Apache Synapse 2008 Carbon OSGified Aug-2016NEL Q4-2016 Ballerina: language spec Apr-2017 0.85 Feb-2017 0.8 tec.preview
  • 6.
    Why stop atusing sequence diagrams to describe programs?
  • 8.
    Ballerina • General purposeprogramming language, but optimized for integration • Strongly typed, concurrent with both text and graphical syntaxes • Modern, network-aware, data-aware, security-aware programming system inspired by Java, Go, Maven, ...
  • 9.
    The Ballerina Language •Graphical/textual parity with ability to switch back and forth • Common integration capabilities are baked into the language: – Deep HTTP/REST/Swagger alignment – Connectors for Web APIs and non-HTTP APIs – Support for JSON, XML, (No)SQL data and mapping • No magic – no weird syntax exceptions, everything is derived from a few key language concepts • Maximize developer productivity and abstraction clarity • Support high performance implementations: low latency, low memory and fast startup
  • 10.
    Hello, World! import ballerina.lang.system; functionmain(string[] args) { system:println("Hello, World!"); }
  • 11.
  • 12.
    Ballerina knows services(and main)! • Two models of programming: service and main • Services are network invoked collections of entry points • Main is regular main()
  • 13.
  • 14.
    Ballerina knows data! •XML, JSON and datatable are built-in data types • All streamed, high performant • Data (type) mapping between Ballerina types, XML, JSON and datatables
  • 15.
    Ballerina knows networkAPIs! • Client and server connectors for HTTP 1.1/2, WebSockets, JMS, (S)FTP(S) and more • Client connectors for BasicAuth, OAuth, AmazonAuth, SOAP • Client connectors for Web APIs: Twitter, GMail, LinkedIn, Facebook, Lambda Functions, …
  • 16.
    Ballerina knows (orrather, is) Swagger! • Ballerina programs’ interface (in HTTP case) is expressed in Swagger – Text syntax, graphical syntax and Swagger syntax are interchangeable • Edit interface anywhere • No more standard limitations of interface first design
  • 17.
    Ballerina knows Docker! •Built in build command to create Docker image with executable Ballerina program package • Run on any container management platform
  • 18.
    Ballerina is highlyextensible! • Code organized into packages like Go • Repository model similar to Maven/NPM/Go giving ability to create ecosystem of connector contributors • Recomposable network connectors
  • 19.
    Ballerina is opensource! • Patent pending technology • Implementation released under Apache License v2.0 – Fork me on GitHub: https://github.com/ballerinalang/ • Community – Users: ballerina-user@googlegroups.com – Slack: #ballerinalang – Twitter: @ballerinalang – StackOverflow: #ballerinalang – Developers: ballerina-dev@googlegroups.com
  • 20.
  • 21.
    Ballerina Concepts • Functions •Services • Resources • Connectors • Actions • Workers
  • 22.
    Modularity: Files &Packages • Package model inspired by Go – package org.wso2.foo; • Packages are defined by the set of all files in a directory • All symbols exposed by any file in the package is referred to with packagename:symbolname – In other words, file names have no meaning in the namespace of the language • To use symbols from a package you must import: – import org.wso2.foo [as xx]; • Packages that start with ballerina.* and ballerinax.* are reserved • Packages will be versioned - details later
  • 23.
    Type System ANY VALUE TYPE INT FLOAT BOOLEAN REFERENCETYPE BUILT-IN USER DEFINED STRUCT ARRAY STRING MAP EXCEPTION MESSAGE XML JSON ITERATOR XMLDOCUMENT DATATABLE
  • 24.
    JSON Support • Variablesof type “json” can hold any JSON value • Optionally, can associate a JSON Schema to the declaration: – json[<json_schema_name>] jsdoc; – Constraints the value to conform to the schema • Useful for type mapping • JSON literals can be used to initialize JSON typed variables – json address_json = `{"name" : "$name", "streetName" : "${street}"}`;
  • 25.
    XML Support • Variablesof type “xml” can hold any XML element • Variables of type “xmldocument” can hold any XML document • Optionally can associate an XML Schema to constrain the value space of XML – xml[<{xsd_namespace_name}type_name}>] e; • XML literals – xmlElement address_xml = `<address><name>${name}</name></address>`;
  • 26.
    Tabular Data Support •Variables of type “datatable” can hold any tabular data coming from a data source • Database connectors to query and produce datatables
  • 27.
    Type Coercion andConversion • Lossless type coercions are automatic – E.g. int -> float • Other type conversions can be invoked with the cast operator – TypeT1 v1; – TypeT2 v2; – v2 = (TypeT2) v1; • Users can define their own type mappers which fit into the language type system and get invoked with the cast operator
  • 28.
    Type Mappers typemapper TypeMapperName(TypeName VariableName) (TypeName) { Statement;+ } (More constraints coming)
  • 29.
    Language Statements • assignment •if • while • break • try/catch/throw • return • action invocation • fork/join • worker initiation/invocation/join/reply
  • 30.
    Fork/Join fork (MessageName) { workerWorkerName (message VariableName) { Statement;+ [reply MessageName;] }+ } [join (JoinCondition) (message[] VariableName) { Statement;* } timeout (Expression) (message[] VariableName) { Statement;* }]
  • 31.
  • 32.
    Worker Interaction worker WorkerName(message m) { Statement;+ [reply MessageName;] } • Send/receive message to coordinate MessageName -> WorkerName; MessageName <- WorkerName;
  • 33.
  • 34.
    Ballerina is notjust the language • Composer with debugging, type mapping • IDE plugins • Docerina • Testerina • (Coming soon) Packerina
  • 35.
    Composer • Textual, graphicaland Swagger editing of Ballerina programs • Runs in the browser – Currently not packaged with embedded Chromium; considering it • Will be hosted in the cloud as well
  • 36.
    IDE Plugins • Available(still WIP) – Atom – Vim – Idea – Sublime Text – VSCode – Adobe Brackets • More to be done! – Send a pull request ☺
  • 37.
    Docerina • Tool togenerate API docs for your Ballerina code • All Ballerina code is documented using Docerina
  • 38.
    Testerina • Unit testand mocking framework for Ballerina
  • 39.
    Packerina • Tool tomanage repositories, manage dependencies and build Ballerina programs • Coming soon under this name .. partly shipping already
  • 40.
  • 41.
    When should Iuse Ballerina? • Write integration microservices – 80-20 rule: if 80% of your service is about integrating with other services, data and APIs then use Ballerina. If its just 20% then use Java / Node / Go / XYZ • Re-compose existing services to be API backends • Write integration scripts – Replacement for shell scripts that use curl too much
  • 42.
  • 43.
  • 44.
    Available now: Ballerinav0.85 Technology Preview • Language runtime – Run once, run one service, run many services (bus) • Developer tools – Composer: browser based graphic/text/Swagger editor and debugger – IDE plugins: Idea, Atom, Vim, Sublime, VSCode, Brackets – Testerina: Unit testing framework – Docerina: API doc generation framework • Connectors
  • 45.
  • 46.
    Next Steps • Download,twirl with it, give us feedback • Engage with the community – Users: ballerina-user@googlegroups.com – Slack: #ballerinalang – Twitter: @ballerinalang – StackOverflow: #ballerinalang – Developers: ballerina-dev@googlegroups.com
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
    Ballerina Concepts: Client& Server Connectors • Ballerina services are attached to network protocols with server connectors • Ballerina programs interact with network endpoints with client connectors – Networked endpoints can mean pretty much anything
  • 53.