File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ FROM docker.io/node:14.16.1
2+ MAINTAINER extra2000 <https://github.com/extra2000>
3+
4+ COPY ./project /srv/project
5+ WORKDIR /srv/project
6+ RUN npm install
Original file line number Diff line number Diff line change 1+ # Sample apps: Redis Pub/Sub
2+
3+ Example how to use Redis for Pub/Sub. Credits to https://medium.com/@ridwanfajar/using-redis-pub-sub-with-node-js-its-quite-easy-c9c8b4dae79f
4+
5+
6+ ## Deploy Redis pod
7+
8+ ```
9+ $ podman play kube --network=sampleapps redis-pod.yaml
10+ ```
11+
12+ To test Redis deployment, execute the following command and make sure the output is ` PONG ` :
13+ ```
14+ $ podman exec -it redis-pod-redis01 redis-cli -a abcde12345 ping
15+ ```
16+
17+
18+ ## Deploy publisher and producer services
19+
20+ ```
21+ $ podman build -t extra2000/redis-pubsub/pubsub .
22+ $ podman play kube --network=sampleapps subscriber-pod.yaml
23+ $ podman play kube --network=sampleapps publisher-pod.yaml
24+ ```
25+
26+ See logs:
27+ ```
28+ $ podman logs subscriber-pod-subscriber
29+ ```
30+
31+
32+ ## To clean up
33+
34+ ```
35+ $ podman pod rm --force publisher-pod subscriber-pod redis-pod
36+ ```
Original file line number Diff line number Diff line change 1+ # Logs
2+ logs
3+ * .log
4+ npm-debug.log *
5+ yarn-debug.log *
6+ yarn-error.log *
7+ lerna-debug.log *
8+
9+ # Diagnostic reports (https://nodejs.org/api/report.html)
10+ report. [0-9 ]* . [0-9 ]* . [0-9 ]* . [0-9 ]* .json
11+
12+ # Runtime data
13+ pids
14+ * .pid
15+ * .seed
16+ * .pid.lock
17+
18+ # Directory for instrumented libs generated by jscoverage/JSCover
19+ lib-cov
20+
21+ # Coverage directory used by tools like istanbul
22+ coverage
23+ * .lcov
24+
25+ # nyc test coverage
26+ .nyc_output
27+
28+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+ .grunt
30+
31+ # Bower dependency directory (https://bower.io/)
32+ bower_components
33+
34+ # node-waf configuration
35+ .lock-wscript
36+
37+ # Compiled binary addons (https://nodejs.org/api/addons.html)
38+ build /Release
39+
40+ # Dependency directories
41+ node_modules /
42+ jspm_packages /
43+
44+ # TypeScript v1 declaration files
45+ typings /
46+
47+ # TypeScript cache
48+ * .tsbuildinfo
49+
50+ # Optional npm cache directory
51+ .npm
52+
53+ # Optional eslint cache
54+ .eslintcache
55+
56+ # Microbundle cache
57+ .rpt2_cache /
58+ .rts2_cache_cjs /
59+ .rts2_cache_es /
60+ .rts2_cache_umd /
61+
62+ # Optional REPL history
63+ .node_repl_history
64+
65+ # Output of 'npm pack'
66+ * .tgz
67+
68+ # Yarn Integrity file
69+ .yarn-integrity
70+
71+ # dotenv environment variables file
72+ .env
73+ .env.test
74+
75+ # parcel-bundler cache (https://parceljs.org/)
76+ .cache
77+
78+ # Next.js build output
79+ .next
80+
81+ # Nuxt.js build / generate output
82+ .nuxt
83+ dist
84+
85+ # Gatsby files
86+ .cache /
87+ # Comment in the public line in if your project uses Gatsby and *not* Next.js
88+ # https://nextjs.org/blog/next-9-1#public-directory-support
89+ # public
90+
91+ # vuepress build output
92+ .vuepress /dist
93+
94+ # Serverless directories
95+ .serverless /
96+
97+ # FuseBox cache
98+ .fusebox /
99+
100+ # DynamoDB Local files
101+ .dynamodb /
102+
103+ # TernJS port file
104+ .tern-port
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " redis-pubsub" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " Redis Pub/Sub example" ,
5+ "author" : " extra2000" ,
6+ "license" : " MIT" ,
7+ "scripts" : {
8+ "publisher" : " node src/publisher.js" ,
9+ "subscriber" : " node src/subscriber.js"
10+ },
11+ "dependencies" : {
12+ "redis" : " ^3.1.2"
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ var redis = require ( "redis" ) ;
2+
3+ const publisher = redis . createClient ( {
4+ host : 'redis-pod.sampleapps' ,
5+ port : '6379' ,
6+ password : 'abcde12345'
7+ } ) ;
8+
9+ publisher . publish ( "notification" , "{\"message\":\"Hello world from Asgardian!\"}" , function ( ) {
10+ process . exit ( 0 ) ;
11+ } ) ;
Original file line number Diff line number Diff line change 1+ var redis = require ( "redis" ) ;
2+
3+ const subscriber = redis . createClient ( {
4+ host : 'redis-pod.sampleapps' ,
5+ port : '6379' ,
6+ password : 'abcde12345'
7+ } ) ;
8+
9+ subscriber . on ( "message" , function ( channel , message ) {
10+ console . log ( "Message: " + message + " on channel: " + channel + " is arrive!" ) ;
11+ } ) ;
12+
13+ subscriber . subscribe ( "notification" ) ;
Original file line number Diff line number Diff line change 1+ apiVersion : v1
2+ kind : Pod
3+ metadata :
4+ name : publisher-pod
5+ spec :
6+ restartPolicy : Never
7+ containers :
8+ - name : publisher
9+ image : extra2000/redis-pubsub/pubsub
10+ command : ['npm', 'run', 'publisher']
Original file line number Diff line number Diff line change 1+ apiVersion : v1
2+ kind : Pod
3+ metadata :
4+ labels :
5+ app : redis-pod
6+ name : redis-pod
7+ spec :
8+ restartPolicy : OnFailure
9+ containers :
10+ - name : redis01
11+ image : docker.io/redis:6.2-alpine
12+ command : ['redis-server', '--requirepass', "abcde12345"]
13+ securityContext :
14+ allowPrivilegeEscalation : false
15+ privileged : false
16+ capabilities :
17+ add : []
18+ drop :
19+ - CAP_MKNOD
20+ - CAP_NET_RAW
21+ - CAP_AUDIT_WRITE
22+ seLinuxOptions : {}
23+ resources :
24+ requests :
25+ memory : 200Mi
26+ limits :
27+ memory : 200Mi
Original file line number Diff line number Diff line change 1+ apiVersion : v1
2+ kind : Pod
3+ metadata :
4+ name : subscriber-pod
5+ spec :
6+ restartPolicy : Never
7+ containers :
8+ - name : subscriber
9+ image : extra2000/redis-pubsub/pubsub
10+ command : ['npm', 'run', 'subscriber']
You can’t perform that action at this time.
0 commit comments