All Projects → sjmf → ng2-stompjs-demo

sjmf / ng2-stompjs-demo

Licence: MIT license
Angular 2 demo using stomp.js in Typescript

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to ng2-stompjs-demo

ng2-mqtt-demo
Angular 2 demo using MQTT.js in Typescript
Stars: ✭ 32 (-23.81%)
Mutual labels:  angular2, angular-cli
Ng Pi Admin
Angular admin http://treesflower.com/ng-pi-admin
Stars: ✭ 131 (+211.9%)
Mutual labels:  angular2, angular-cli
Anvel
Angular 2 Laravel Starter Kit
Stars: ✭ 102 (+142.86%)
Mutual labels:  angular2, angular-cli
Coreui Free Angular Admin Template
CoreUI Angular is free Angular 2+ admin template based on Bootstrap 4
Stars: ✭ 1,279 (+2945.24%)
Mutual labels:  angular2, angular-cli
Angular5 Seed
Angular5 Seed for Application
Stars: ✭ 222 (+428.57%)
Mutual labels:  angular2, angular-cli
Clever Bootstrap 4 Admin Template With Angularjs Angular 2 Support
Clever is Boostrap 4 Admin Template with Angular 2 and AngularJS support
Stars: ✭ 98 (+133.33%)
Mutual labels:  angular2, angular-cli
AuthGuard
Example repo for guarding routes post
Stars: ✭ 42 (+0%)
Mutual labels:  angular2, angular-cli
Nebular
💥 Customizable Angular UI Library based on Eva Design System 🌚✨Dark Mode
Stars: ✭ 7,368 (+17442.86%)
Mutual labels:  angular2, angular-cli
Angular4 Docker Example
Efficiently Dockerized Angular CLI example app
Stars: ✭ 212 (+404.76%)
Mutual labels:  angular2, angular-cli
Angular2 Crud Rest
Sample Angular (2.x and 4.x) app: CRUD example + routing
Stars: ✭ 152 (+261.9%)
Mutual labels:  angular2, angular-cli
Angular Full Stack
Angular Full Stack project built using Angular, Express, Mongoose and Node. Whole stack in TypeScript.
Stars: ✭ 1,261 (+2902.38%)
Mutual labels:  angular2, angular-cli
Ng Pokedex
🐵 Pokedex progressive web app built with Angular
Stars: ✭ 245 (+483.33%)
Mutual labels:  angular2, angular-cli
Angular2
Angular 2 Seed
Stars: ✭ 75 (+78.57%)
Mutual labels:  angular2, angular-cli
Angular4 Primeng Admin
angular4-primeng-admin @angular/cli开发的后台模板
Stars: ✭ 99 (+135.71%)
Mutual labels:  angular2, angular-cli
Root Bootstrap 4 Admin Template With Angularjs Angular 2 Support
Root is Boostrap 4 Admin Template with Angular 2 and AngularJS support
Stars: ✭ 54 (+28.57%)
Mutual labels:  angular2, angular-cli
Ng Packaged
An Angular library packaged by ng-packagr
Stars: ✭ 109 (+159.52%)
Mutual labels:  angular2, angular-cli
Angular2 Express Starter
Angular 8 and Express 👪 ( Heroku ready )
Stars: ✭ 565 (+1245.24%)
Mutual labels:  angular2, angular-cli
Ng Sticky
Angular 4 sticky, have header or any component sticky easy to use.
Stars: ✭ 25 (-40.48%)
Mutual labels:  angular2, angular-cli
Paper Kit 2 Angular
Free Bootstrap 4 UI Kit for Angular 2+
Stars: ✭ 133 (+216.67%)
Mutual labels:  angular2, angular-cli
Blog Angular
Angular 笔记
Stars: ✭ 238 (+466.67%)
Mutual labels:  angular2, angular-cli

STOMP.js Angular 2 Demo App

A demo application using Angular 2 in Typescript and STOMP.js, generated with angular-cli.

This demo app implements a more ng2-faithful way of connecting to a message queue and subscribing to messages from a STOMP topic. Uses the Typescript interface definition for Jeff Mesnil's excellent STOMP.js JavaScript library, a STOMPService which subscribes to messages, and an example 'raw data' component which uses the Observable type to data-bind messages to the DOM.

For a demo using MQTT instead of STOMP, see https://github.com/sjmf/ng2-mqtt-demo

To get more help on the angular-cli use ng --help or go check out the Angular-CLI README.

Quick Start

As well as the following, you will also need the angular-cli and a message broker supporting STOMP, the Simple Text Oriented Messaging Protocol. This example was built using RabbitMQ WebSTOMP but other brokers will also work. (Shameless self-plug: if you want SSL with your RabbitMQ socks, you might want to read my blog post.)

To get started running this app locally (assuming you've already got angular-cli):

# Clone the repo
git clone https://github.com/sjmf/ng2-stompjs-demo
# cd into it
cd ng2-stompjs-demo
# Install the packages from package.json
npm install

You will also need to edit the app/api/config.json configuration file to set the correct connection parameters for your message broker. When you've done this, you can run the application locally:

# Run the application locally
ng serve

Then http://localhost:4200 should open in your browser. The app will automatically reload if you change any of the source files.

You can override the default port by changing it in the .ember-cli file.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the -prod flag for a production build.

Layout

The source is located under the app folder:

├── src                                          * Source folder
│   ├── api                                      * Example API folder (static for demo)
│   │   └── config.json                          * Configuration file for STOMP
│   │
│   ├── app                                      * Application folder
│   │   ├── components                           * Components folder
│   │   │   ├── rawdata                          * Example data streaming component folder
│   │   │   └── status                           * STOMP Status component folder
│   │   │
│   │   ├── services                             * Services folder
│   │   │   ├── config                           * Config service folder (retrieves the configuration)
│   │   │   └── stomp                            * STOMP service folder (ng2 definition for a STOMP configuration)
│   │   │
│   │   ├── app.component.css                    * Component css file
│   │   ├── app.component.html                   * Component html file
│   │   ├── app.component.spec.ts                * Component testings
│   │   ├── app.component.ts                     * Top-level app-root component
│   │   ├── app.module.ts                        * App module definition
│   │   └── index.ts                             * Indexing file
│   │
│   ├── assets                                   * Assets folder
│   │   └── .gitkeep                             * Placeholder to include the folder to source control
│   │
│   ├── environments                             * Environment settings folder
│   │   ├── environment.prod.ts                  * Production environment settings
│   │   └── environment.ts                       * Development environment settings
│   │
│   ├── index.html                               * The root page served to browser
│   ├── main.ts                                  * App bootstrap
│   ├── polyfills.ts                             * Polyfills file
│   ├── styles.css                               * Main css file
│   ├── tsconfig.app.json                        * App Typescript transpiler options 
│   └── typings.d.ts                             * Typescript typings definition file
│
├── .angular-cli.json                            * Angular CLI configuration file
├── package.json                                 * Package info and list of dependencies to install
├── tsconfig.json                                * Main Typescript transpiler options 
└── tslint.json                                  * Typescript Linter configuration file

Excluded from this partial tree for brevity: sub-component .ts .html etc files under folders, testing framework files, and the e2e End to End testing folder containing app behaviour testings and definitions. The node_modules directory will also be generated for the installed node packages.)

Extending

The example data streaming component provides a demonstration of how to use the STOMPService to subscribe to a data stream. At its' core, the STOMPService makes available an Observable which the RawDataComponent uses in its own template, and additionally subscribes its' own on_next method to.

A barebones set-up of the service could run from a component's ngOnInit method, and might look something like this:

this._stompService.configure( config, () => console.log("connected") );
this._stompService.try_connect();

Our RawDataComponent then copies a reference to the public member messages, which can be used with a template variable and the |async pipe to update the template in real time.

The instantiating component must provide an instance of STOMPService. This implementation also uses a ConfigService to retrieve the STOMP connection variables from a json file, with the intention that other clients might like to route this request to an API along with some form of user token.

The STOMP connection status is also fed-back to the application user via a BehaviorSubject observable, implemented following the model used in this Angular2 stocks app. If the connection fails, the application will retry every 5 seconds until it reopens.

Contributing

Very happy to accept suggestions for improvement (or even pull requests!). This project represents my first run-in with Typescript and Angular 2, so while I feel like I've learned a lot it's possible that I've messed up somewhere. Raise an issue and let me know!

Licence

MIT Licence. Essentially: do what you like with it, but give credit if credit's due, and it's not my fault if this code eats your product/machine/whatever.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].