RamblingCookieMonster / PSRabbitMq

PowerShell module to send and receive messages from a RabbitMq server
http://ramblingcookiemonster.github.io/RabbitMQ-Intro/
MIT License
47 stars 29 forks source link

Stored Message using PSRabbitMq has Powershell wrapper XML when reading #25

Closed NealWalters closed 6 years ago

NealWalters commented 6 years ago

Without the details of the security and servername, I'm sending a message like this:

$Exchange = "D.Data.Integrations.Topic"
$RoutingKey = "D.Data.Echo.BSSR.Legacy204Outbound"
$message = get-content "d:\Tests\EDI204_from_WCFSQLPollingEDIStaging_CTII_Original.xml"
Write-Host "Message = $message" 
Send-RabbitMQMessage -Exchange $Exchange -Key $RoutingKey -InputObject $message -vhost base -Persistent @Params
Write-Host "Sent Message to $RoutingKey "

When I read it using PSRabbitMQ it looks okay. But when doing a Get Message from RabbitMQ web interface (or BizTalk Server) the message has been wrapped with a lot of XML.

Example XML:

<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
  <Obj RefId="0">
    <TN RefId="0">
      <T>System.Object[]</T>
      <T>System.Array</T>
      <T>System.Object</T>
    </TN>
    <LST>
      <Obj RefId="1">
        <S>&lt;EGL_204Out_Sql xmlns="http://EGL.BizTalk.Common.Schemas.EGL_204Out_SQL"&gt;  </S>
        <MS>
          <S N="PSPath">D:\GitLTLShipmentOut_Dev\Echo.BSSR.Gateway.LTLShipmentOut\Echo.BSSR.Gateway.LTLShipmentOut.Transforms\Tests\EDI204_from_WCFSQLPollingEDIStaging_CTII_Original.xml</S>
          <S N="PSParentPath">D:\GitLTLShipmentOut_Dev\Echo.BSSR.Gateway.LTLShipmentOut\Echo.BSSR.Gateway.LTLShipmentOut.Transforms\Tests</S>
          <S N="PSChildName">EDI204_from_WCFSQLPollingEDIStaging_CTII_Original.xml</S>
          <Obj N="PSDrive" RefId="2">
            <TN RefId="1">
              <T>System.Management.Automation.PSDriveInfo</T>
              <T>System.Object</T>
            </TN>
            <ToString>D</ToString>
            <Props>
              <S N="CurrentLocation"></S>
              <S N="Name">D</S>
              <Obj N="Provider" RefId="3">
                <TN RefId="2">
                  <T>System.Management.Automation.ProviderInfo</T>
                  <T>System.Object</T>
                </TN>
                <ToString>Microsoft.PowerShell.Core\FileSystem</ToString>
                <Props>

I find my data in there, for example I have a city name of Ontario. In my XML: <N401>ONTARIO</N401>

In the above XML:

      <Obj RefId="102">
        <S>_x0009__x0009__x0009__x0009__x0009_&lt;N401&gt;ONTARIO RDC&lt;/N401&gt;</S>
        <MS>
          <S N="PSPath">D:\GitLTLShipmentOut_Dev\Echo.BSSR.Gateway.LTLShipmentOut\Echo.BSSR.Gateway.LTLShipmentOut.Transforms\Tests\EDI204_from_WCFSQLPollingEDIStaging_CTII_Original.xml</S>
          <S N="PSParentPath">D:\GitLTLShipmentOut_Dev\Echo.BSSR.Gateway.LTLShipmentOut\Echo.BSSR.Gateway.LTLShipmentOut.Transforms\Tests</S>
          <S N="PSChildName">EDI204_from_WCFSQLPollingEDIStaging_CTII_Original.xml</S>
          <Ref N="PSDrive" RefId="2" />
          <Ref N="PSProvider" RefId="3" />
          <I64 N="ReadCount">98</I64>
        </MS>
      </Obj>

How do I get the message to be stored in my simple original XML without all that Powershell XML wrapper "stuff" around it?

Thanks, Neal Walters

gpduck commented 6 years ago

Try using -SerializeAs "text/plain" and you'll also probably need to use Get-Content -Raw to prevent the XML being turned into an array of strings.

By default Send-RabbitMqMessage assumes you'll be trying to send an object (and that PowerShell will be on both ends) and so it runs the input through Export-CliXML. Then in Wait-RabbitMqMessage if the content type is application/clixml+xml it will run the XML through Import-Clixml so that it can spit an object back out on the other side.

NealWalters commented 6 years ago

Adding ' -SerializeAs "text/plain" ' to the Send-RabbitMqMessage worked great. No need to change the Get-Content.

Thanks! Neal