package main

import (
	"encoding/json"
	"flag"
	"fmt"

	nats "github.com/nats-io/go-nats"
	"github.com/regner/albiondata-client/lib"
)

var natsURL string

func init() {
	flag.StringVar(
		&natsURL,
		"i",
		"nats://ingest.albion-data.com:4222",
		"NATS URL to subscribe to.",
	)
}

func dumpMarketOrders(m *nats.Msg) {
	morders := &lib.MarketUpload{}
	if err := json.Unmarshal(m.Data, morders); err != nil {
		fmt.Printf("%v\n", err)
	}

	for _, order := range morders.Orders {
		jb, _ := json.Marshal(order)
		fmt.Printf("%d %s\n", order.LocationID, string(jb))
	}
}

func main() {
	flag.Parse()

	nc, _ := nats.Connect(natsURL)
	defer nc.Close()

	marketCh := make(chan *nats.Msg, 64)
	marketSub, err := nc.ChanSubscribe("marketorders.ingest", marketCh)
	if err != nil {
		fmt.Printf("%v\n", err)
		return
	}
	defer marketSub.Unsubscribe()

	for {
		select {
		case msg := <-marketCh:
			dumpMarketOrders(msg)
		}
	}
}

package main

import (
	"encoding/json"
	"flag"
	"fmt"

	nats "github.com/nats-io/go-nats"
	"github.com/regner/albiondata-client/lib"
)

var natsURL string

func init() {
	flag.StringVar(
		&natsURL,
		"i",
		"nats://localhost:2222",
		"NATS URL to subscribe to.",
	)
}

func dumpMarketOrders(m *nats.Msg) {
	morders := &lib.MarketUpload{}
	if err := json.Unmarshal(m.Data, morders); err != nil {
		fmt.Printf("%v\n", err)
	}

	for _, order := range morders.Orders {
		jb, _ := json.Marshal(order)
		fmt.Printf("%d %s\n", order.LocationID, string(jb))
	}
}

func main() {
	flag.Parse()

	nc, _ := nats.Connect(natsURL)
	defer nc.Close()

	marketCh := make(chan *nats.Msg, 64)
	marketSub, err := nc.ChanSubscribe("marketorders", marketCh)
	if err != nil {
		fmt.Printf("%v\n", err)
		return
	}
	defer marketSub.Unsubscribe()

	for {
		select {
		case msg := <-marketCh:
			dumpMarketOrders(msg)
		}
	}
}

--- 
+++ 
@@ -15,7 +15,7 @@
 	flag.StringVar(
 		&natsURL,
 		"i",
-		"nats://localhost:2222",
+		"nats://ingest.albion-data.com:4222",
 		"NATS URL to subscribe to.",
 	)
 }
@@ -39,7 +39,7 @@
 	defer nc.Close()
 
 	marketCh := make(chan *nats.Msg, 64)
-	marketSub, err := nc.ChanSubscribe("marketorders", marketCh)
+	marketSub, err := nc.ChanSubscribe("marketorders.ingest", marketCh)
 	if err != nil {
 		fmt.Printf("%v\n", err)
 		return
Update the default server for the nats dumper and subscribe to the ingest
