You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by olsonpm <ol...@uwec.edu> on 2011/03/22 20:21:44 UTC

IConnection.start() - optional?

I was trying to implement a persistent producer using NMS and ActiveMQ.  I
realized the function isStarted wasn't returning true, even though my
messages were successfully being sent.  I chalked this up to not calling
connection.start().  However, if the connection isn't running, how are the
messages sending?

Here's the following code that runs as intended
-----------------------------------

Imports System
Imports System.Collections.Generic
Imports System.Text

Imports Apache.NMS.ActiveMQ
Imports Apache.NMS

Module Module1

    Private Const URI As String = "myURI"
    Private Const DEST As String = "myQueue"

    Sub Main()

        Console.Write("press any key to start: ")
        Console.ReadKey()
        Console.WriteLine(vbNewLine)

        Dim df As ConnectionFactory = New ConnectionFactory(URI)
        Dim conn As IConnection = df.CreateConnection()
        Using conn
            Dim session As ISession = conn.CreateSession
            Using session
                If (conn.IsStarted) Then
                    Console.WriteLine("connection has started") '<--doesn't
display
                End If
                Dim prod As IMessageProducer = session.CreateProducer(New
Commands.ActiveMQQueue(DEST))
                Dim msg As ITextMessage = prod.CreateTextMessage()
                msg.Text = "Hello world"
                msg.Properties("OriginUnit") = "3039"
                msg.Properties("OriginDept") = "MME"
                msg.Properties("MessageType") = "AutomatedPalletScan"
                Console.WriteLine("Sending: " & msg.Text)
                prod.Send(msg)

                Console.Write(vbNewLine & "press any key to end: ")
                Console.ReadKey()
            End Using
        End Using
    End Sub

End Module


--
View this message in context: http://activemq.2283324.n4.nabble.com/IConnection-start-optional-tp3397472p3397472.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: IConnection.start() - optional?

Posted by olsonpm <ol...@uwec.edu>.
Yeah - I noticed the NMS documentation is extremely thin, with a few
tutorials here and there around google.  I will use JMS as a reference from
now on.

--
View this message in context: http://activemq.2283324.n4.nabble.com/IConnection-start-optional-tp3397472p3397662.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: IConnection.start() - optional?

Posted by Timothy Bish <ta...@gmail.com>.
On Tue, 2011-03-22 at 13:00 -0700, olsonpm wrote:
> I'm very new to AMQ - would you mind going into a little more detail?  I'm
> not understanding the cases in which you would/wouldn't start a connection.
> 
> thank you for your help,
> Phil
> 

>From the JMS API Documentation for Connection (NMS is modeled on JMS)

"A JMS client typically creates a connection, one or more sessions, and
a number of message producers and consumers. When a connection is
created, it is in stopped mode. That means that no messages are being
delivered.

It is typical to leave the connection in stopped mode until setup is
complete (that is, until all message consumers have been created). At
that point, the client calls the connection's start method, and messages
begin arriving at the connection's consumers. This setup convention
minimizes any client confusion that may result from asynchronous message
delivery while the client is still in the process of setting itself up.

A connection can be started immediately, and the setup can be done
afterwards. Clients that do this must be prepared to handle asynchronous
message delivery while they are still in the process of setting up.

A message producer can send messages while a connection is stopped. "

You might want to spend some time reading about the JMS API as the .NET
client API operates using the same basic rules.

Regards


-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/



Re: IConnection.start() - optional?

Posted by olsonpm <ol...@uwec.edu>.
I'm very new to AMQ - would you mind going into a little more detail?  I'm
not understanding the cases in which you would/wouldn't start a connection.

thank you for your help,
Phil

--
View this message in context: http://activemq.2283324.n4.nabble.com/IConnection-start-optional-tp3397472p3397577.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: IConnection.start() - optional?

Posted by Timothy Bish <ta...@gmail.com>.
On Tue, 2011-03-22 at 12:21 -0700, olsonpm wrote:
> I was trying to implement a persistent producer using NMS and ActiveMQ.  I
> realized the function isStarted wasn't returning true, even though my
> messages were successfully being sent.  I chalked this up to not calling
> connection.start().  However, if the connection isn't running, how are the
> messages sending?

Connection start / stop applies only to the dispatch of Messages to
consumers.  A client can send messages without starting a Connection.

Regards
Tim

> 
> Here's the following code that runs as intended
> -----------------------------------
> 
> Imports System
> Imports System.Collections.Generic
> Imports System.Text
> 
> Imports Apache.NMS.ActiveMQ
> Imports Apache.NMS
> 
> Module Module1
> 
>     Private Const URI As String = "myURI"
>     Private Const DEST As String = "myQueue"
> 
>     Sub Main()
> 
>         Console.Write("press any key to start: ")
>         Console.ReadKey()
>         Console.WriteLine(vbNewLine)
> 
>         Dim df As ConnectionFactory = New ConnectionFactory(URI)
>         Dim conn As IConnection = df.CreateConnection()
>         Using conn
>             Dim session As ISession = conn.CreateSession
>             Using session
>                 If (conn.IsStarted) Then
>                     Console.WriteLine("connection has started") '<--doesn't
> display
>                 End If
>                 Dim prod As IMessageProducer = session.CreateProducer(New
> Commands.ActiveMQQueue(DEST))
>                 Dim msg As ITextMessage = prod.CreateTextMessage()
>                 msg.Text = "Hello world"
>                 msg.Properties("OriginUnit") = "3039"
>                 msg.Properties("OriginDept") = "MME"
>                 msg.Properties("MessageType") = "AutomatedPalletScan"
>                 Console.WriteLine("Sending: " & msg.Text)
>                 prod.Send(msg)
> 
>                 Console.Write(vbNewLine & "press any key to end: ")
>                 Console.ReadKey()
>             End Using
>         End Using
>     End Sub
> 
> End Module
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/IConnection-start-optional-tp3397472p3397472.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.

-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/