1+ <codeTemplateLibrary version =" 3.4.0" >
2+ <id >ca9c7efd-2329-4248-bb9a-0271554baeaf</id >
3+ <name >Route With Sources</name >
4+ <revision >2</revision >
5+ <lastModified >
6+ <time >1718998568183</time >
7+ <timezone >America/New_York</timezone >
8+ </lastModified >
9+ <description >Replacement methods for router.routeMessage* functions with added functionality to automatically insert the current channel
10+ and message ids into the source chain in the sourceMap of the downstream channel in the same way that a Channel Writer would
11+ add that information.
12+ </description >
13+ <includeNewChannels >true</includeNewChannels >
14+ <enabledChannelIds />
15+ <disabledChannelIds />
16+ <codeTemplates >
17+ <codeTemplate version =" 3.4.0" >
18+ <id >c487e335-9148-4d12-9c0f-c8e5bf10010b</id >
19+ <name >createRawMessage(message, sourceMap, destinationSet)</name >
20+ <revision >2</revision >
21+ <lastModified >
22+ <time >1719010706913</time >
23+ <timezone >America/New_York</timezone >
24+ </lastModified >
25+ <type >FUNCTION</type >
26+ <contextSet >
27+ <delegate >
28+ <contextType >SOURCE_RECEIVER</contextType >
29+ <contextType >CHANNEL_POSTPROCESSOR</contextType >
30+ <contextType >GLOBAL_DEPLOY</contextType >
31+ <contextType >GLOBAL_UNDEPLOY</contextType >
32+ <contextType >GLOBAL_PREPROCESSOR</contextType >
33+ <contextType >CHANNEL_BATCH</contextType >
34+ <contextType >CHANNEL_UNDEPLOY</contextType >
35+ <contextType >CHANNEL_DEPLOY</contextType >
36+ <contextType >DESTINATION_RESPONSE_TRANSFORMER</contextType >
37+ <contextType >DESTINATION_DISPATCHER</contextType >
38+ <contextType >CHANNEL_ATTACHMENT</contextType >
39+ <contextType >GLOBAL_POSTPROCESSOR</contextType >
40+ <contextType >CHANNEL_PREPROCESSOR</contextType >
41+ <contextType >SOURCE_FILTER_TRANSFORMER</contextType >
42+ <contextType >DESTINATION_FILTER_TRANSFORMER</contextType >
43+ </delegate >
44+ </contextSet >
45+ <code >/**
46+ Create a RawMessage with the specified content, sourceMap, and destinationSet. Information about the
47+ chain of source channel Ids and source message Ids will be included in the sourceMap of the new
48+ RawMessage automatically in a similar manner as if a Channel Writer was being used.
49+
50+ If this is called from a context where there is no messageId, a value of -1 will be used.
51+
52+ If this is called from a context where there is no channelId, a value of " NONE" will be used.
53+
54+ @copyright 2023,2024 Tony Germano
55+ @license MPL-2.0
56+
57+ @param {string|byte[]} message - The content of the message to be sent, textual or binary.
58+ @param {Object|java.util.Map} sourceMap - A map containing entries to include in the sourceMap of
59+ the RawMessage (optional).
60+ @param {Array< number> |java.util.Collection< Number> } destinationSet - A collection of integers
61+ (metadata IDs) representing which destinations to dispatch the message to. Null may be passed to
62+ indicate all destinations. If unspecified, all destinations is the default (optional).
63+ @return {RawMessage} - A RawMessage object containing the message, source, and destination
64+ information.
65+ */
66+ function createRawMessage(message, sourceMap, destinationSet) {
67+ if (typeof destinationSet === ' undefined' ) destinationSet = null
68+ if (sourceMap == null) sourceMap = java.util.Collections.emptyMap()
69+
70+ const sourceChannelIds = $(' sourceChannelIds' ) ? new java.util.ArrayList($(' sourceChannelIds' ))
71+ : $(' sourceChannelId' ) ? new java.util.ArrayList([$(' sourceChannelId' )])
72+ : new java.util.ArrayList()
73+ const sourceMessageIds = $(' sourceMessageIds' ) ? new java.util.ArrayList($(' sourceMessageIds' ))
74+ : $(' sourceMessageId' ) ? new java.util.ArrayList([$(' sourceMessageId' )])
75+ : new java.util.ArrayList()
76+
77+ const newSourceMap = new java.util.HashMap(sourceMap),
78+ _channelId = typeof channelId !== ' undefined' ? channelId : " NONE" ,
79+ messageId = new java.lang.Long(typeof connectorMessage !== ' undefined' ? connectorMessage.messageId : -1)
80+
81+ sourceChannelIds.add(_channelId)
82+ sourceMessageIds.add(messageId)
83+
84+ newSourceMap.putAll({
85+ sourceChannelIds: sourceChannelIds,
86+ sourceChannelId: _channelId,
87+ sourceMessageIds: sourceMessageIds,
88+ sourceMessageId: messageId
89+ })
90+
91+ return new RawMessage(message, destinationSet, newSourceMap)
92+ }</code >
93+ </codeTemplate >
94+ <codeTemplate version =" 3.4.0" >
95+ <id >f9472423-7df4-4ba9-a002-9029ec99e4dc</id >
96+ <name >routeMessage(channelName, message, sourceMap, destinationSet)</name >
97+ <revision >2</revision >
98+ <lastModified >
99+ <time >1719010706787</time >
100+ <timezone >America/New_York</timezone >
101+ </lastModified >
102+ <type >FUNCTION</type >
103+ <contextSet >
104+ <delegate >
105+ <contextType >SOURCE_RECEIVER</contextType >
106+ <contextType >CHANNEL_POSTPROCESSOR</contextType >
107+ <contextType >GLOBAL_DEPLOY</contextType >
108+ <contextType >GLOBAL_UNDEPLOY</contextType >
109+ <contextType >GLOBAL_PREPROCESSOR</contextType >
110+ <contextType >CHANNEL_BATCH</contextType >
111+ <contextType >CHANNEL_UNDEPLOY</contextType >
112+ <contextType >CHANNEL_DEPLOY</contextType >
113+ <contextType >DESTINATION_RESPONSE_TRANSFORMER</contextType >
114+ <contextType >DESTINATION_DISPATCHER</contextType >
115+ <contextType >CHANNEL_ATTACHMENT</contextType >
116+ <contextType >GLOBAL_POSTPROCESSOR</contextType >
117+ <contextType >CHANNEL_PREPROCESSOR</contextType >
118+ <contextType >SOURCE_FILTER_TRANSFORMER</contextType >
119+ <contextType >DESTINATION_FILTER_TRANSFORMER</contextType >
120+ </delegate >
121+ </contextSet >
122+ <code >/**
123+ Route a message to the specified channelName. Information about the chain of source channel Ids and
124+ source message Ids will be included in the sourceMap of the downstream message automatically in a
125+ similar manner as if a Channel Writer was being used.
126+
127+ @copyright 2023,2024 Tony Germano
128+ @license MPL-2.0
129+
130+ @param {string} channelName - The name of the channel to which to route the message.
131+ @param {string|byte[]} message - The content of the message to be sent, textual or binary.
132+ @param {Object|java.util.Map} sourceMap - A map containing entries to include in the sourceMap of
133+ the sent message (optional).
134+ @param {Array< number> |java.util.Collection< Number> } destinationSet - A collection of integers
135+ (metadata IDs) representing which destinations to dispatch the message to. Null may be passed to
136+ indicate all destinations. If unspecified, all destinations is the default (optional).
137+ @return {Response} - The Response object returned by the channel.
138+ */
139+ function routeMessage(channelName, message, sourceMap, destinationSet) {
140+ return router.routeMessage(channelName, createRawMessage(message, sourceMap, destinationSet))
141+ }</code >
142+ </codeTemplate >
143+ <codeTemplate version =" 3.4.0" >
144+ <id >09025c2d-2909-49cd-9382-94e81fb65f4d</id >
145+ <name >routeMessageByChannelId(channelId, message, sourceMap, destinationSet)</name >
146+ <revision >2</revision >
147+ <lastModified >
148+ <time >1719010707014</time >
149+ <timezone >America/New_York</timezone >
150+ </lastModified >
151+ <type >FUNCTION</type >
152+ <contextSet >
153+ <delegate >
154+ <contextType >SOURCE_RECEIVER</contextType >
155+ <contextType >CHANNEL_POSTPROCESSOR</contextType >
156+ <contextType >GLOBAL_DEPLOY</contextType >
157+ <contextType >GLOBAL_UNDEPLOY</contextType >
158+ <contextType >GLOBAL_PREPROCESSOR</contextType >
159+ <contextType >CHANNEL_BATCH</contextType >
160+ <contextType >CHANNEL_UNDEPLOY</contextType >
161+ <contextType >CHANNEL_DEPLOY</contextType >
162+ <contextType >DESTINATION_RESPONSE_TRANSFORMER</contextType >
163+ <contextType >DESTINATION_DISPATCHER</contextType >
164+ <contextType >CHANNEL_ATTACHMENT</contextType >
165+ <contextType >GLOBAL_POSTPROCESSOR</contextType >
166+ <contextType >CHANNEL_PREPROCESSOR</contextType >
167+ <contextType >SOURCE_FILTER_TRANSFORMER</contextType >
168+ <contextType >DESTINATION_FILTER_TRANSFORMER</contextType >
169+ </delegate >
170+ </contextSet >
171+ <code >/**
172+ Route a message to the specified channelId. Information about the chain of source channel Ids and
173+ source message Ids will be included in the sourceMap of the downstream message automatically in a
174+ similar manner as if a Channel Writer was being used.
175+
176+ @copyright 2023,2024 Tony Germano
177+ @license MPL-2.0
178+
179+ @param {string} channelId - The unique identifier of the channel to which to route the message.
180+ @param {string|byte[]} message - The content of the message to be sent, textual or binary.
181+ @param {Object|java.util.Map} sourceMap - A map containing entries to include in the sourceMap of
182+ the sent message (optional).
183+ @param {Array< number> |java.util.Collection< Number> } destinationSet - A collection of integers
184+ (metadata IDs) representing which destinations to dispatch the message to. Null may be passed to
185+ indicate all destinations. If unspecified, all destinations is the default (optional).
186+ @return {Response} - The Response object returned by the channel.
187+ */
188+ function routeMessageByChannelId(channelId, message, sourceMap, destinationSet) {
189+ return router.routeMessageByChannelId(channelId, createRawMessage(message, sourceMap, destinationSet))
190+ }</code >
191+ </codeTemplate >
192+ </codeTemplates >
193+ </codeTemplateLibrary >
0 commit comments