0

I was wondering if there was a way to set up a queue in c# to receive custom structs. For example, I want to receive and store messages of the following structure into a queue:

public struct TPCANMsg
{
    /// <summary>
    /// 11/29-bit message identifier
    /// </summary>
    public uint ID;
    /// <summary>
    /// Type of the message
    /// </summary>
    [MarshalAs(UnmanagedType.U1)]
    public TPCANMessageType MSGTYPE;  
    /// <summary>
    /// Data Length Code of the message (0..8)
    /// </summary>
    public byte LEN;      
    /// <summary>
    /// Data of the message (DATA[0]..DATA[7])
    /// </summary>
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
    public byte[] DATA;   
}

How would I go about setting up a MSMQ to receive and process that data type?

Thanks very much

JS61095
  • 1
  • 1
  • Do you have to use MSMQ? I strongly recommend you have a look at RabbitMQ. – Eyal Perry Jun 20 '18 at 19:26
  • Hi Eyal. To answer your question, no I do not have to use MSMQ.Thanks for your suggestion! I will definitely read up on RabbitMQ. – JS61095 Jun 20 '18 at 19:35
  • That is the right decision. They even have a docker image and NET STANDARD compliant drivers. I have written a full fledged IOT app with it and there is no limit to what you can accomplish. – Eyal Perry Jun 21 '18 at 05:37
  • @EyalPerry that may be the case but what if the OP is operating in a pure windows environment, and needs only very basic messaging capabilities. MSMQ would make sense in that scenario as it's built into windows. – tom redfern Jun 21 '18 at 10:22
  • @tomredfern I always prefer native solutions, unless there's a chance of cross-platform needs. Also, I always prefer commonplace protocols (RMQ supports a lot of those, with little to no configuration required) over server specific ones. Since the chance that someone is building a WINDOWS ONLY app today is slim, I directed the OP towards a solution that is cross-platform out of the box. Ex: a React.js UI + services which run as deamons on an IoT device. – Eyal Perry Jun 21 '18 at 13:17
  • Serialize the struct to ProtoBuff, XML, JSON or something else and send it to the queue. Receive the message from the queue and deserialize it back to the struct. – Kjell-Åke Gafvelin Mar 28 '19 at 22:17

0 Answers0