Skip to content

Commit f2dfde5

Browse files
committed
move topic to configuration file
1 parent a1418b1 commit f2dfde5

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

cmd/mq2p.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func main() {
4747
sm.Update(mqp)
4848
}
4949

50-
if token := c.Subscribe("topic", 0, messageHandler); token.Wait() && token.Error() != nil {
50+
if token := c.Subscribe(conf.MqConfig.Topic, 0, messageHandler); token.Wait() && token.Error() != nil {
5151
fmt.Println(token.Error())
5252
os.Exit(1)
5353
}

config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mq:
22
server: tcp://127.0.0.1:1883
3+
topic: topic
34
metrics:
45
- mq_name: simple_metric
56
prom_name: simple_metric_prom

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Config struct {
1616

1717
type MqConfig struct {
1818
Server string
19+
Topic string
1920
}
2021

2122
// ReadConfig reads the provided file for configuration

pkg/config/config_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ import (
77
manager "github.ibm.com/chandergovind/mq2p/pkg/metric-manager"
88
)
99

10-
func TestSimpleConfigNoMetrics(t *testing.T) {
10+
func TestSimpleConfigMQPortion(t *testing.T) {
1111
assert := assert.New(t)
1212

1313
configString := []byte(`
1414
mq:
1515
server: dummy_server
16+
topic: dummy_topic
1617
`)
1718
cfg, err := ParseConfig(configString)
1819
assert.Nil(err)
1920
assert.Equal("dummy_server", cfg.MqConfig.Server)
21+
assert.Equal("dummy_topic", cfg.MqConfig.Topic)
2022
assert.Empty(cfg.Metrics)
2123

2224
}

0 commit comments

Comments
 (0)