Use ByteArrayRawSerializer instead of ByteArrayCrLfSerializer - spring

I am not very familiair with Spring Integration (I am taking the project over from a colleague) but I am encountering the following problem that probably is being caused by the use of the ByteArrayCrLfSerializer;
The message that is ultimately send through the TCP connection ends with an additional '\r\n'.
According to the documentation, we need to use the ByteArrayRawSerializer.
My question is;
How can we overrule/overwrite/set the ByteArrayRawSerializer to being used instead of the ByteArrayCrLfSerializer?
The message to be serialized one-on-one without additional characters.

Related

Restrict incoming message signature for message broker

My goal is to define some API using REST arch style and spring boot in order to store messages to activemq message broker. I would like to have REST on top of message broker to have possibility to restrict message format. Actually the main goal is to allow only messages which contains all nessessary fields inside message payload.
Could you please suggest if it is rigth way to go and if there are any alternative ways to achive the goal?
Yes. This is a REST-to-Messaging Proxy design and can work just fine for the use case you described.
Alternatively, you could do the message inspection in the broker, but since this inspection sounds logic-related, it is best suited for something running outside the broker.

Using one Message Handle for several MQ message cause memory leaks?

Has anyone worked with MQ from RPG?
The problem is as follows. There are several messages in the queue. All of them are with RFH2 header. Each header contains a set of NameValueData.
I am creating a Message Handle and passing it to MQGET. Then I retrieve Properties using MQINQMP.
Question. When I read several messages in a loop, using the same Message Handle instance for all (without freeing it and re-creating it for each message), will I have memory leaks?
The IBM MQ Message Properties API is designed to be used in the following way.
MQOPEN
MQCRTMH
start-loop
MQGET
MQINQMP
end-loop
MQCLOSE
MQDLTMH
You can see this demonstrated in the IBM supplied 'C' sample amqsbcg0.c. I know your question is for RPG, but the underlying API is meant to work the same for all languages.

Retrieving data from database using spring integration JDBC without poll

Currently learning spring integration, I want to retrieve information from a MySQL database to use inside an int:service-activator, or an int:splitter .
Unfortunately, it would seem that most examples and documentation is based around the idea of using an int-jdbc:inbound-channel-adapter, which in itself requires a poller. I don't want to poll a database, but rather retrieve specific data based on the payload of an existing message originating from an int:gateway. This data would then be used to further modify the payload, or assist in how the message is split.
I tried using int-jdbc:outbound-gateway, as the description states:
... jdbc.JdbcOutboundGateway' for updating a database in response to a message on the request channel, and/or for retrieving data from the database ...
This implies that it can be used for retrieval of data only and not just updates, but as I implement it, there's a complaint that at least one update statement is required:
And so I'm currently sitting with a faulty prototype that initially looks like so:
The circled piece being the non-functioning int-jdbc:outbound-gateway.
My end goal is to, based on the payload coming from the incomingGateway (in the picture above), retrieve some information from a MySQL database, and use that data to split the message in the analyzerSplitter, or to perhaps modify the payload using an int:service-activator. This should then all be linked up to a int-jdbc:message-store which I believe could assist with performance. I do not wish to poll the database on a regular basis, and I do not wish to update anything in the database.
By testing using the polling int-jdbc:inbound-channel-adapter, I am confident that my datasource bean is set up correctly and the query can execute.
How would I go about correctly setting up such behaviour in spring integration?
If you want to proceed with the flow after updating the database, you can simply use a JdbcTemplate in a method invoked by a service activator, or, if it's the end of the flow, use an outbound channel adapter.
The outbound channel adapter is the inverse of the inbound: its role is to handle a message and use it to execute a SQL query. By default, the message payload and headers are available as input parameters to the query, as the following example shows:
...

Spring Integration JMS Threadsafe

I'm pretty new to Spring Integration and still trying to get my head around it. Right now I'm just trying to understand if the example I've found here is actually safe across multiple threads:
https://github.com/spring-projects/spring-integration-samples/blob/master/basic/jms/src/test/java/org/springframework/integration/samples/jms/ChannelAdapterDemoTest.java
My use case is as follows:
Send request to queue with JMS Reply-to as a temporary queue
Wait for response to be received on the temporary queue
Need this to happen synchronously within a method -- I don't want to split it up and make it asynchronous across several methods
Will the above example work for this? If not, am I barking up the wrong tree?
Thanks in advance.
That sample is pretty simple; it just sends the message to stdout so, yes, it's perfectly thread safe.
For the request/reply scenario you are talking about, you need to use a <gateway/> - see the other example in that sample project. In that case, you can see that the message is handled by 'demoBean' which, again, is perfectly thread safe.
For a real application, the thread-safetyness depends on the code in the services invoked by the flow receiving the message.
If you wish, you can use Spring Integration on the client side too (with an outbound gateway).

message coming from tcp socket processed in chunks not as a whole

I am trying to establish a tcp socket connection to a spring integraton gateway. The byte arrat messages are rather large and I have setup the ByteArrayLengthHeaderSerializer to handle it by modding the property maxMessageSize to handle the messages. However, the messages are instead being handled in chunks, the first only 28 bytes in size before the service-activator is called. I know that there is an Aggregator that could be used but I was thinking I might have setup the integration components incorrectly. I am using the basic spring jars 3.0.5 and the integration 2.0.2 and the integrationContext.xml is here:
Does anyone have any suggestions
Thanks
The source had a mangled header value which gave a false reading as to the size of the message coming. Once the header was fixed there was no problem.

Resources