Skip to content

Instantly share code, notes, and snippets.

@parthghiya
parthghiya / MEAN2
Created January 31, 2017 10:25
server js snippet for MEAN 2
// Get dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
// Get our API routes
const api = require('./server/routes/api');
const app = express();
@parthghiya
parthghiya / socketservice.ts
Created February 7, 2017 13:05
socket io service Angular 2
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import * as io from "socket.io-client";
import { IMessage, ISocketItem } from "../../models";
@Injectable()
export class SocketService {
private name: string;
private host: string = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port;
@parthghiya
parthghiya / component1.ts
Created September 22, 2017 16:54
Caching Service Data Using Replayable Subject (RxJS) In Angular
import { TestService } from './../services/test.service';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-comp1',
templateUrl: './comp1.component.html',
styleUrls: ['./comp1.component.css']
})
export class Comp1Component implements OnInit {
@parthghiya
parthghiya / .htaccess
Created November 5, 2017 14:52
Sample Apache Configuration for Redirections to migrated or existing application based on rules
RewriteEngine On
# Serve feature from new service for internal network
RewriteCond expr "%{HTTP:X-FORWARDED-FOR} -ipmatch '171.78.205.170/24'"
RewriteRule ^/feature/(.*)$ ${NEW_SERVICE_URL}/$1 [P,L]
# Proxy everything else to legacy application
RewriteRule ^/(.*) ${LEGACY_URL}/$1 [P]
ProxyPassReverse / ${LEGACY_URL}/
@parthghiya
parthghiya / gist:777c2b423c9c8faf0d427fd7a3eeb95b
Created November 5, 2017 17:20
Circuit breaker in Node JS
/*
Sample Implementation of Circuit Breaker using hystrixjs in NodeJS
It uses reactive principles
Link : https://www.npmjs.com/package/hystrixjs
*/
var CommandsFactory = require('hystrixjs').commandFactory;
var serviceCommand = CommandsFactory.getOrCreate("Service on port :" + service.port + ":" + port)
.circuitBreakerErrorThresholdPercentage(service.errorThreshold)
.timeout(service.timeout)
@parthghiya
parthghiya / app.yaml
Created November 5, 2017 20:04
sample yml file for microservices configuration with memory resources limit and cpu limit
apiVersion: v1
kind: Pod
metadata:
name: shopping-management
spec:
containers:
- name: shopping-management
image: shopping-service
resources:
requests:
@parthghiya
parthghiya / async_queue.js
Created November 8, 2017 07:42
Sample Queue Implementation to achieve Asychronous Messaging communication
var q = 'tasks';
var open = require('amqplib').connect('amqp://localhost');
// Publisher
open.then(function(conn) {
return conn.createChannel();
}).then(function(ch) {
return ch.assertQueue(q).then(function(ok) {
@parthghiya
parthghiya / Aggregator.js
Created November 8, 2017 11:55
API Aggragation sample in microservices
/*
* Parses the request and dispatches multiple concurrent requests to each
* internal endpoint. Results are aggregated and returned.
*/
function serviceDispatch(req, res) {
var parsedUrl = url.parse(req.url);
/*Service is where we maintain the requests which we want to aggregate/
Service.findOne({ url: parsedUrl.pathname }, function(err, service) {