Skip to content

mjdilworth/random

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

random

random json doc generator in go

random.exe: a go program to generate random JSON data and put it into a local(127.0.0.1) mongodb database called test using a collection called test_data. You can specify on the console how many records to create.
For each JSON record there is a Value entry which is randomly set to either a 1 or 0 with a 10% probability that the value will be a 1. This is achieved using the rand.Float64() function.
var num int
if rand.Float64() < 0.1 {
	num = 1
} else {
	num = 0
}
publisher_test.py: a python script to read all records form the mongodb test_data collection. It then loops through the returned collection and every second it will put one of these onto a rabbitMQ queue called test_queue. https://github.com/mjdilworth/publisher.git
consumer.exe: a go program which connects to the rabbitMQ test_queue and consumes messages. When it receives a message that has a "Value" attribute which is a "1" it writes out to a text file (/tmp/stratagem_golang_output.txt) the timestamp (placed on the queue) Thu Jan 29 08:48:11 +0000 UTC 2015, the JSON object message ID 54c9f00c14339b3c3ea5052c and the string "Got a 1!". these are delimitated by the pipe symbol. https://github.com/mjdilworth/consumer.git
Overall notes

All installations used default parameters

For Python we use pika for rabbitMQ and pymongo for mongodb

these are installed using pip

pip install pika
pip install pymongo

for go you need to install the Go RabbtMQ client ``` go get github.com/streadway/amqp ```

and the mgo driver

go get gopkg.in/mgo.v2

To export test data from mongodb

C:\Program Files\MongoDB 2.6 Standard\bin>mongoexport --db test --collection test_data --csv  -f _id,Value,DT --out /tmp/test_data.csv
connected to: 127.0.0.1
exported 100 records

About

random json doc generator in go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages