' 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 SendAMQ
    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 QNAME As String = "TestQ"
        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 q As IQueue = ses.GetQueue(QNAME)
                        Using sender As IMessageProducer = ses.CreateProducer(q)
                            For i As Integer = 0 To 2
                                Dim smsg As IMessage = ses.CreateTextMessage(PAYLOAD)
                                sender.Send(smsg)
                            Next
                        End Using
                    End Using
                End Using
            End Using
        End Sub
    End Class
End Namespace
