' Collection of code snippets by Arne Vajhøj 
' (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
﻿Imports System

Imports Apache.NMS
Imports Apache.NMS.ActiveMQ

Namespace PubAMQ
    Public Class Program
        Private Const SERVER As String = "tcp://localhost:61616"
        Private Const UN As String = "arne"
        Private Const PW As String = "topsecret"
        Private Const TNAME As String = "TestT"
        Private Const PAYLOAD As String = "<data>" & vbCr & vbLf & "    <id>123</id>" & vbCr & vbLf & "    <name>ABC</name>" & vbCr & vbLf & "</data>"
        Public Shared Sub Main(args As String())
            Dim confac As IConnectionFactory = New ConnectionFactory(New Uri(SERVER))
            Using con As IConnection = confac.CreateConnection(UN, PW)
                con.Start()
                Using ses As ISession = con.CreateSession(AcknowledgementMode.AutoAcknowledge)
                    Using t As ITopic = ses.GetTopic(TNAME)
                        Using publisher As IMessageProducer = ses.CreateProducer(t)
                            For i As Integer = 0 To 2
                                Dim smsg As IMessage = ses.CreateTextMessage(PAYLOAD)
                                publisher.Send(smsg)
                            Next
                        End Using
                    End Using
                End Using
            End Using
        End Sub
    End Class
End Namespace
