Return-Path: Delivered-To: apmail-geronimo-activemq-users-archive@www.apache.org Received: (qmail 13510 invoked from network); 15 Jan 2007 09:53:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Jan 2007 09:53:42 -0000 Received: (qmail 9333 invoked by uid 500); 15 Jan 2007 09:53:48 -0000 Delivered-To: apmail-geronimo-activemq-users-archive@geronimo.apache.org Received: (qmail 9313 invoked by uid 500); 15 Jan 2007 09:53:48 -0000 Mailing-List: contact activemq-users-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-users@geronimo.apache.org Delivered-To: mailing list activemq-users@geronimo.apache.org Received: (qmail 9303 invoked by uid 99); 15 Jan 2007 09:53:48 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jan 2007 01:53:48 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of james.strachan@gmail.com designates 66.249.92.174 as permitted sender) Received: from [66.249.92.174] (HELO ug-out-1314.google.com) (66.249.92.174) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jan 2007 01:53:39 -0800 Received: by ug-out-1314.google.com with SMTP id m2so1630753ugc for ; Mon, 15 Jan 2007 01:53:17 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=GvmYNrJP7B/Zwco1nnUoIpJdumMUyGgZVH82OunzcsXUxGZeqaR4uv48n42O2S7bwqZaYedp2IbvP7kjmcJvGGxQfYhAW2aY96x1kKR8hAb9Pfpm7Jefw7HkyzIKpfzngdHmiGFcmu3xZWFWARgT2umSzot2Rt1IQTXO8wrrPp8= Received: by 10.78.187.17 with SMTP id k17mr2407792huf.1168854748439; Mon, 15 Jan 2007 01:52:28 -0800 (PST) Received: by 10.78.155.6 with HTTP; Mon, 15 Jan 2007 01:52:27 -0800 (PST) Message-ID: Date: Mon, 15 Jan 2007 09:52:27 +0000 From: "James Strachan" To: activemq-users@geronimo.apache.org Subject: Re: What am I missing ... In-Reply-To: <8307110.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <8307110.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org I'm not sure I understand why this is happening; I wonder if you tried another client (either the web console or a Java consumer), do you get the text of the message ok? On 1/12/07, Kyle Hodgson wrote: > > I'm writing a simple windows form app that a) sends a message b) has an event > handler for receiving that message and c) can check a queue for any messages > that are yet un-handled. > > For some reason, the event handler is firing the event onMessage(), but the > text of the incoming message is lost. > > Public Sub sendOne() > producer = session.CreateProducer(destination) > producer.Persistent = True > > Dim message As ActiveMQTextMessage > message = session.CreateTextMessage("w00t!") > message.NMSCorrelationID = "abc" > producer.Send(message) > > End Sub > > (Works, and when I run this through the debugger I can see the text of the > message no problem with a breakpoint at the producer.Send line - so the text > has not been lost yet.) > > Sub New(ByVal arg1 As Form1) > > mainform = arg1 > factory = New ConnectionFactory(New Uri("tcp://10.78.78.1:61636")) > connection = factory.CreateConnection() > session = connection.CreateSession() > destination = session.GetQueue("lyceum") > consumer = session.CreateConsumer(destination) > > AddHandler consumer.Listener, AddressOf gotOne > mainform.setStatus("listener added.") > > End Sub > > This successfully adds an event handler gotOne to my class. > > Private Sub gotOne(ByVal message As NMS.IMessage) > Dim amqMessage As ActiveMQTextMessage > amqMessage = CType(message, ActiveMQTextMessage) > mainform.setStatus("Got one.") > mainform.setMessages("begin" + amqMessage.Text + "end") > End Sub > > gotOne works - I can see the "Got one." message and I see the "begin" when a > message comes in. But the original message is gone (debugger shows the > contents of amqMessage.Text as "") and for some odd reason the word "end" > does not show up. I put begin and end there just in case there were tab or > space characters I wasn't seeing. I've tried amqMessage.toString, which did > show me lots of information about the message, but the text of the message > was still not present. I was suspecting that it's the conversion from > IMessage to ActiveMQTextMessage but I have other code examples that seem to > indicate that I've done that correctly. > > Any ideas? > > The only weird thing about our setup I can think of is that I had to import > the Visual Studio 2005 source code of the .NET client available on this site > to Visual Studio 2003 to make it usable in our projects. But I've > successfully used these DLL's in other projects, and the above behavior did > not exhibit itself. > > Here's the full source code: > > Imports ActiveMQ > Imports NMS > Imports ActiveMQ.Commands > > Public Class Form1 > Inherits System.Windows.Forms.Form > > #Region " Windows Form Designer generated code " > > Dim L As Object > > Public Sub New() > MyBase.New() > > 'This call is required by the Windows Form Designer. > InitializeComponent() > > 'Add any initialization after the InitializeComponent() call > > End Sub > > 'Form overrides dispose to clean up the component list. > Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) > If disposing Then > If Not (components Is Nothing) Then > components.Dispose() > End If > End If > MyBase.Dispose(disposing) > End Sub > > 'Required by the Windows Form Designer > Private components As System.ComponentModel.IContainer > > 'NOTE: The following procedure is required by the Windows Form Designer > 'It can be modified using the Windows Form Designer. > 'Do not modify it using the code editor. > Friend WithEvents lbStatus As System.Windows.Forms.ListBox > Friend WithEvents lbMessages As System.Windows.Forms.ListBox > Friend WithEvents Button1 As System.Windows.Forms.Button > Friend WithEvents Button2 As System.Windows.Forms.Button > Private Sub > InitializeComponent() > Me.lbStatus = New System.Windows.Forms.ListBox > Me.lbMessages = New System.Windows.Forms.ListBox > Me.Button1 = New System.Windows.Forms.Button > Me.Button2 = New System.Windows.Forms.Button > Me.SuspendLayout() > ' > 'lbStatus > ' > Me.lbStatus.Location = New System.Drawing.Point(0, 8) > Me.lbStatus.Name = "lbStatus" > Me.lbStatus.Size = New System.Drawing.Size(656, 173) > Me.lbStatus.TabIndex = 0 > ' > 'lbMessages > ' > Me.lbMessages.HorizontalScrollbar = True > Me.lbMessages.Location = New System.Drawing.Point(0, 184) > Me.lbMessages.Name = "lbMessages" > Me.lbMessages.Size = New System.Drawing.Size(656, 329) > Me.lbMessages.TabIndex = 1 > ' > 'Button1 > ' > Me.Button1.Location = New System.Drawing.Point(688, 48) > Me.Button1.Name = "Button1" > Me.Button1.TabIndex = 2 > Me.Button1.Text = "DeQueue" > ' > 'Button2 > ' > Me.Button2.Location = New System.Drawing.Point(688, 88) > Me.Button2.Name = "Button2" > Me.Button2.TabIndex = 3 > Me.Button2.Text = "Send One" > ' > 'Form1 > ' > Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) > Me.ClientSize = New System.Drawing.Size(800, 517) > Me.Controls.Add(Me.Button2) > Me.Controls.Add(Me.Button1) > Me.Controls.Add(Me.lbMessages) > Me.Controls.Add(Me.lbStatus) > Me.Name = "Form1" > Me.Text = "Form1" > Me.ResumeLayout(False) > > End Sub > > #End Region > > > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > > setStatus("Initialized.") > > L = New ML(Me) > > End Sub > > > Sub setStatus(ByVal message As String) > > If lbStatus.Items.Count = 100 Then lbStatus.Items.RemoveAt(99) > lbStatus.Items.Insert(0, Now & " " & message) > > End Sub > > Sub setMessages(ByVal message As String) > > If lbMessages.Items.Count = 100 Then lbMessages.Items.RemoveAt(99) > lbMessages.Items.Insert(0, Now & " " & message) > > End Sub > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > > L.goGetEm() > > End Sub > > Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button2.Click > L.sendOne() > End Sub > End Class > > Imports ActiveMQ > Imports ActiveMQ.Commands > Imports NMS > Imports System > > Public Class ML > > Dim factory As IConnectionFactory > Dim connection As IConnection > Dim session As ISession > Dim destination As IDestination > Dim listener As MessageListener > Dim mainform As Form1 > Dim consumer As IMessageConsumer > Dim producer As IMessageProducer > Sub New(ByVal arg1 As Form1) > > mainform = arg1 > factory = New ConnectionFactory(New Uri("tcp://10.78.78.1:61636")) > connection = factory.CreateConnection() > session = connection.CreateSession() > destination = session.GetQueue("lyceum") > consumer = session.CreateConsumer(destination) > > AddHandler consumer.Listener, AddressOf gotOne > mainform.setStatus("listener added.") > > End Sub > > Public Sub sendOne() > producer = session.CreateProducer(destination) > producer.Persistent = True > > Dim message As ActiveMQTextMessage > message = session.CreateTextMessage("w00t!") > message.NMSCorrelationID = "abc" > producer.Send(message) > > End Sub > > Private Sub gotOne(ByVal message As NMS.IMessage) > Dim amqMessage As ActiveMQTextMessage > amqMessage = CType(message, ActiveMQTextMessage) > mainform.setStatus("Got one.") > mainform.setMessages("begin" + amqMessage.Text + "end") > End Sub > > Public Sub goGetEm() > '// lets consume a message > 'ActiveMQTextMessage message = (ActiveMQTextMessage) > consumer.Receive(); > 'if (message == null) > '{ > 'Console.WriteLine("No message received!"); > '} > 'Else > '{ > 'Console.WriteLine("Received message with ID: " + > message.NMSMessageId); > 'Console.WriteLine("Received message with text: " + message.Text); > '} > Dim message = New ActiveMQTextMessage > message = Me.consumer.Receive > If message Is Nothing Then > mainform.setStatus("No message waiting.") > Else > mainform.setMessages(message.text) > Dim fileWriter As New System.IO.StreamWriter("c:\file.txt") > fileWriter.Write(message.text) > fileWriter.Close() > End If > > > End Sub > End Class > > -- > View this message in context: http://www.nabble.com/What-am-I-missing-...-tf2968575.html#a8307110 > Sent from the ActiveMQ - User mailing list archive at Nabble.com. > > -- James ------- http://radio.weblogs.com/0112098/