none
Sending a plain string to a Message Queue

    Question

  • I have created a package that will do all of the data work I need and I end up with a user variable (say 'XMLString') of a string type that I need to write to a local private queue.  I can set up the Message Queue task without a problem, but I can't get it to write my exact string to the queue.  Without using 2000 format, I get the SOAP format, which won't work since I need it to send the exact string.  I have experimented with using both a string message that is set in an expression and directly passing the string variable.  The former writes the string with a space in between every character in my string, and the latter adds a GUID, the variable name, and the variable type to the beginning of my string.  I am required to be able to write exactly what is in XMLString onto the queue.  I have tried to use a Script task and the MessageQueue task as well, but haven't gotten that to write to the queue yet.  I believe the issue might relate to needing to pass an object to the Message Queue task instead of a string, but I'm not sure how to get my string into an object that it can process.  Does anyone have any idea as to how I can get my exact string written to MSMQ?  Thanks.
    Wednesday, May 27, 2009 9:07 PM

Answers

  • Thanks again for your help.  That seems to confirm what I had thought, and I think I'm getting closer.  I stopped using the Message Queue task and I'm trying out the Script task.  Here is what I have code-wise so far:

    Public Sub Main()
            Dim queueMessage As Message
            Dim theQueue As MessageQueue
            Dim messageStream As IO.StreamWriter
    
            Try
                theQueue = New MessageQueue(".\private$\queuename")
            Catch
                MsgBox("set up queue - " + Err.Description)
                Dts.TaskResult() = Dts.Results.Failure
                Exit Sub
            End Try
    
            Try
                messageStream = New IO.StreamWriter(New IO.MemoryStream)
                messageStream.Write(Dts.Variables("XMLString").Value.ToString())
                messageStream.Flush()
    
                queueMessage = New Message()
                queueMessage.BodyStream = messageStream.BaseStream
            Catch
                MsgBox("set up message - " + Err.Description)
                Dts.TaskResult() = Dts.Results.Failure
                Exit Sub
            End Try
    
            Try
                theQueue.Send(queueMessage)
            Catch
                MsgBox("send message - " + Err.Description)
                Dts.TaskResult() = Dts.Results.Failure
                Exit Sub
            End Try
    
            Dts.TaskResult() = Dts.Results.Success
    
        End Sub

    I finally have it running with no errors, but nothing appears in the queue.  Can you see anything obvious I'm doing wrong?
    Friday, May 29, 2009 4:19 PM
  • Ok, I finally got it to work.  I needed to add "MessageQueueTransactionType.Single" as the transaction type parameter when sending the Message to the MessageQueue.  Now I just have to get the other application I'm dealing with to accept the data I'm passing in.
    Friday, May 29, 2009 5:10 PM

All replies

  • I have created a package that will do all of the data work I need and I end up with a user variable (say 'XMLString') of a string type that I need to write to a local private queue.  I can set up the Message Queue task without a problem, but I can't get it to write my exact string to the queue.  Without using 2000 format, I get the SOAP format, which won't work since I need it to send the exact string.  I have experimented with using both a string message that is set in an expression and directly passing the string variable.  The former writes the string with a space in between every character in my string, and the latter adds a GUID, the variable name, and the variable type to the beginning of my string.  I am required to be able to write exactly what is in XMLString onto the queue.  I have tried to use a Script task and the MessageQueue task as well, but haven't gotten that to write to the queue yet.  I believe the issue might relate to needing to pass an object to the Message Queue task instead of a string, but I'm not sure how to get my string into an object that it can process.  Does anyone have any idea as to how I can get my exact string written to MSMQ?  Thanks.

    This is not the correct place to ask this question. Try here or here .

    SSIS Tasks Components Scripts | http://www.cozyroc.com/
    Thursday, May 28, 2009 3:30 PM
  • My problem is with the usage of the Message Queue task in SSIS, wouldn't the SSIS forum be the proper place for this question?  I might not have phrased my question clearly.  I want to use the Message Queue task to write a particular string onto a local private queue, but it prepends some extra information.  Is it not possible to use the Message Queue task to put an exact string onto a queue?
    Thursday, May 28, 2009 6:00 PM
  • Oh. I'm sorry . My mistake. I think you have to review the queue where you send your message. The queue is inserting the SOAP envelope around your message. You may find this article helpful.

    SSIS Tasks Components Scripts | http://www.cozyroc.com/
    Thursday, May 28, 2009 7:15 PM
  • Thanks again for your help.  That seems to confirm what I had thought, and I think I'm getting closer.  I stopped using the Message Queue task and I'm trying out the Script task.  Here is what I have code-wise so far:

    Public Sub Main()
            Dim queueMessage As Message
            Dim theQueue As MessageQueue
            Dim messageStream As IO.StreamWriter
    
            Try
                theQueue = New MessageQueue(".\private$\queuename")
            Catch
                MsgBox("set up queue - " + Err.Description)
                Dts.TaskResult() = Dts.Results.Failure
                Exit Sub
            End Try
    
            Try
                messageStream = New IO.StreamWriter(New IO.MemoryStream)
                messageStream.Write(Dts.Variables("XMLString").Value.ToString())
                messageStream.Flush()
    
                queueMessage = New Message()
                queueMessage.BodyStream = messageStream.BaseStream
            Catch
                MsgBox("set up message - " + Err.Description)
                Dts.TaskResult() = Dts.Results.Failure
                Exit Sub
            End Try
    
            Try
                theQueue.Send(queueMessage)
            Catch
                MsgBox("send message - " + Err.Description)
                Dts.TaskResult() = Dts.Results.Failure
                Exit Sub
            End Try
    
            Dts.TaskResult() = Dts.Results.Success
    
        End Sub

    I finally have it running with no errors, but nothing appears in the queue.  Can you see anything obvious I'm doing wrong?
    Friday, May 29, 2009 4:19 PM
  • Ok, I finally got it to work.  I needed to add "MessageQueueTransactionType.Single" as the transaction type parameter when sending the Message to the MessageQueue.  Now I just have to get the other application I'm dealing with to accept the data I'm passing in.
    Friday, May 29, 2009 5:10 PM