golang, java, linux

Apache ActiveMQ ? Old and boring? how about doing it with Golang ?

Got a task today, ActiveMQ server is somehow failing to process messages, and the reason is “unknown” of course (thats why I happened to be told to solve it).

Well, my first idea was: I will build a Maven project, integrate some jars and get this AMQ running smoothly.

Then I created a maven project, but it seems that the Maven gods are not with me today and I got into a defect 😦
ClassNotFoundException: org.slf4j.LoggerFactory
I did quick search and found several people having similar problems defect, defect2 defect3 defect4.

I mean, a ClassNotFoundException is basic issue…but this is not the point. The point is I’m tired of losing my time with Maven and I want to be effective, I want to build something that does not need a build management tool.

Seriously ? YES.

So, I have no time to lose, I have to deliver this in few minutes because I’m a contractor and if I don’t deliver I don’t get paid. (Just like that). And I can’t just tell the client: "oh by the way I'm loosing time here because Maven can't find a freaking dependency that was supposed to be there".

I just can't afford to be fighting with Maven just to send a MSG over TCP right ?

Well it took me 5 minutes to develop a script here that does the job, it sends a msg to AMQ and another script gets the message. (NO maven required).

I used Go Stomp, (wonderful project by the way).


conn, err := stomp.Dial("tcp", "localhost:61613")
if err != nil {
fmt.Println(err)
}
err = conn.Send(
"/queue/test-1", // destination
"text/plain", // content-type
[]byte("Test message #1")) // body
if err != nil {
fmt.Println(err)
}

And to get the message ?


conn, err := stomp.Dial("tcp", "localhost:61613")
if err != nil {
fmt.Println(err)
}
sub, err := conn.Subscribe("/queue/test-1", stomp.AckClient)
if err != nil {
fmt.Println(err)
}
for {
msg := <-sub.C
fmt.Println(msg)

// acknowledge the message
err = conn.Ack(msg)
if err != nil {
fmt.Println(err)
}
}

I’m quite satisfied that I was able to work around the problem and get some script fast and direct to the point.

Source code

Thanks.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s