Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Add service for sticker browsing, searching, and popularity tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
chlowell committed May 18, 2017
1 parent 13c214e commit 836ab1b
Show file tree
Hide file tree
Showing 14 changed files with 806 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@
"localRoot": "${workspaceRoot}/sessionService",
"remoteRoot": "/app/",
"restart": true
},
{
"type": "node",
"request": "attach",
"name": "Attach (sticker service)",
"port": 5959,
"localRoot": "${workspaceRoot}/stickerService/",
"remoteRoot": "/app/",
"restart": true
}
]
}
5 changes: 5 additions & 0 deletions stickerService/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:7.9.0-alpine
RUN npm install -g nodemon
WORKDIR /app
ADD package.json .
RUN npm install
9 changes: 9 additions & 0 deletions stickerService/debug.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
KAFKA_HOST=zookeeper:2181
KAFKA_TOPIC=TrendingStickers
MONGO_URL=mongodb://mongo:27017/getStickersDemo
NODE_ENV=development
PORT=2000
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_TLS=
49 changes: 49 additions & 0 deletions stickerService/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: '2'

services:
mongo-stickers:
image: mongo:3.5.5
ports:
- 27017:27017

sticker-service:
depends_on:
- kafka
- mongo-stickers
- redis
build:
context: ${PROJECT_ROOT}/stickerService
dockerfile: Dockerfile.dev
container_name: sticker-service
env_file:
- debug.env
command: nodemon --debug=0.0.0.0:5959 --legacy-watch index.js
ports:
- 2000:2000
- 5959:5959
volumes:
- ${PROJECT_ROOT}/stickerService:/app:ro
- /app/node_modules

zookeeper:
image: wurstmeister/zookeeper
ports:
- 2181:2181

kafka:
depends_on:
- zookeeper
image: wurstmeister/kafka
ports:
- 9092:9092
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka
KAFKA_CREATE_TOPICS: TrendingStickers:1:1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock

redis:
image: redis:3.2.8-alpine
ports:
- 6379:6379
43 changes: 43 additions & 0 deletions stickerService/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const express = require('express');
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
const itemPopularity = require('./itemPopularity');

const search = require('./routes/search');
const stickers = require('./routes/stickers');
const top = require('./routes/top');

if (app.get('env') === 'development') {
const db = require('./mongodb');
const path = require('path');
const test = require('./routes/test');

// give the db some time to get ready, then initialize it with some data
// TODO use the gulp task for this (in an init container perhaps)
setTimeout(() => db.initializeDatabaseAsync()
.then(console.log('db initialized with seed data')), 20000);

app.use(express.static(path.join(__dirname, 'test')));
app.use('/test', test);
}

app.use('/search', search);
app.use('/stickers', stickers);
app.use('/top', top);

// websocket stuff: send the current top items to all new connections,
// and update everyone when the top items change
io.on('connection', function sendTrendingItems(socket) {
console.log(`new socket ${socket.id} connected from ${socket.client.conn.remoteAddress}`);
itemPopularity.topKAsync(5)
.then(top5 => socket.send(top5))
.catch(error => console.log(`sending top items failed: ${error}`));
});
itemPopularity.on('newTopItems', topItems => io.send(topItems));

server.listen(process.env.PORT, () => {
console.log(`Sticker service listening on ${server.address().port}`);
});
170 changes: 170 additions & 0 deletions stickerService/initial-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
module.exports = [

{
id: '1',
tags: [ 'Deployment' ],
name: 'Docker',
description: 'The Docker container-based platform deployment system',
author: 'Docker',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/docker.png'
}, {
id: '2',
tags: [ 'Service' ],
name: 'Trello',
description: 'The Trello project management service',
author: 'Trello',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/trello.png'
}, {
id: '3',
tags: [ 'Framework' ],
name: 'Ember',
description: 'The Ember JavaScript framework',
author: 'Ember',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/ember.png'
}, {
id: '4',
tags: [ 'Language' ],
name: 'Go',
description: 'The Go programming langauge',
author: 'Google',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/go.png'
}, {
id: '5',
tags: [ 'Language' ],
name: 'TypeScript',
description: 'The TypeScript programming langauge',
author: 'Microsoft',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/typescript.png'
}, {
id: '6',
tags: [ 'Tooling' ],
name: 'Git',
description: 'The Git version control system',
author: 'Git',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/git.png'
}, {
id: '7',
tags: [ 'Language' ],
name: 'Markdown',
description: 'The Markdown document language',
author: 'Markdown',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/markdown.png'
}, {
id: '8',
tags: [ 'Deployment' ],
name: 'Travis CI',
description: 'The Travis CI integration service',
author: 'Travis CI',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/travisci.png'
}, {
id: '9',
tags: [ 'Deployment' ],
name: 'Kubernetes',
description: 'The Kubernetes container deployment system',
author: 'Kubernetes',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/kubernetes.png'
}, {
id: '10',
tags: [ 'Protocol' ],
name: 'OAuth',
description: 'The OAuth authentication protocol',
author: 'OAuth',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/oauth.png'
}, {
id: '11',
tags: [ 'Service' ],
name: 'MailChimp',
description: 'MailChimp provides email marketing services',
author: 'MailChimp',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/mailchimp.png'
}, {
id: '12',
tags: [ 'Framework' ],
name: 'Bootstrap',
description: 'The Bootstrap CSS client framework',
author: 'Twitter',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/bootstrap.png'
}, {
id: '13',
tags: [ 'Language' ],
name: 'Rust',
description: 'The Rust programming langauge',
author: 'Mozilla',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/rust.png'
}, {
id: '14',
tags: [ 'Service' ],
name: 'Open Source Initiative',
description: 'The Open Source Initiative non-profit foundation',
author: 'OSI',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/osi.png'
}, {
id: '15',
tags: [ 'Language' ],
name: 'Ruby',
description: 'The Ruby programming langauge',
author: 'Ruby Community',
size: {
width: '2in',
height: '2in'
},
image: '/img/logo/ruby.png'
}

];
Loading

0 comments on commit 836ab1b

Please sign in to comment.