Federico Mariani created CAMEL-25888:
----------------------------------------

             Summary: camel-pubnub - the producer should not use the consumer's 
channel header
                 Key: CAMEL-25888
                 URL: https://issues.apache.org/jira/browse/CAMEL-25888
             Project: Camel
          Issue Type: Bug
          Components: camel-pubnub
            Reporter: Federico Mariani
             Fix For: 4.24.0, 4.22.3, 4.18.6


h3. Current behaviour

The PubNub consumer sets the {{CamelPubNubChannel}} header 
({{PubNubConstants.CHANNEL}}) to the channel each received message or presence 
event arrived on ({{PubNubConsumer}}). The same header is also read by the 
producer: {{PubNubProducer.getChannel()}} prefers {{CamelPubNubChannel}} over 
the {{channel}} configured on the endpoint, for every operation (publish, fire, 
getHistory, getState, setState, hereNow), and there is no option to turn this 
off.

As a result, a route that consumes from one PubNub endpoint and sends to a 
second PubNub endpoint does not use the second endpoint's configured channel. 
The exchange still carries the consumer's {{CamelPubNubChannel}} header, so the 
producer sends to the channel the message was received on. With a wildcard 
({{foo.*}}) or a comma-separated channel list on the consumer, the channel used 
by the producer changes from message to message.

{code:java}
from("pubnub:inbound.*?subscribeKey=...")
    .to("pubnub:outbound?publishKey=...&subscribeKey=...");
// today the message is published to the channel it was received on (e.g. 
inbound.a),
// not to "outbound"
{code}

The consumer header is metadata about where a message came from; it should not 
decide where a downstream producer sends it. Other components keep these two 
concerns apart (for example camel-kafka's {{kafka.TOPIC}} / 
{{kafka.OVERRIDE_TOPIC}}).

h3. Expected behaviour

* The producer uses the channel configured on its endpoint.
* A new producer header, {{CamelPubNubOverrideChannel}} 
({{PubNubConstants.OVERRIDE_CHANNEL}}), lets a route choose a different channel 
explicitly.
* The consumer keeps setting {{CamelPubNubChannel}} as before.

h3. Proposed change

* {{PubNubConstants}}: keep {{CHANNEL}} ({{CamelPubNubChannel}}) as consumer 
metadata; add {{OVERRIDE_CHANNEL = "CamelPubNubOverrideChannel"}} with 
{{@Metadata(label = "producer", description = "The channel to use instead of 
the channel configured on the endpoint.")}}.
* {{PubNubProducer.getChannel()}}: read only {{CamelPubNubOverrideChannel}}, 
falling back to {{PubNubConfiguration.getChannel()}}; it no longer reads 
{{CamelPubNubChannel}}.
* Regenerate {{pubnub.json}}, the catalog and the endpoint DSL header constants.
* Upgrade guide: routes that set {{CamelPubNubChannel}} to pick the producer's 
channel must use {{CamelPubNubOverrideChannel}} instead (4.24, and the 4.22.3 
and 4.18.6 entries).

h3. Tests

* {{PubNubPublishTest}}: an exchange carrying {{CamelPubNubChannel}} is 
published to the endpoint's configured channel; {{CamelPubNubOverrideChannel}} 
selects the channel when set.
* A consumer-to-producer route test: a message received on one channel and 
forwarded to a second pubnub endpoint is published to that endpoint's 
configured channel.
* Existing consumer assertions on {{CamelPubNubChannel}} 
({{PubNubSubscriberTest}}, {{PubNubPresenceTest}}) stay unchanged.

The behaviour dates back to the first version of the component and is the same 
on main, camel-4.22.x and camel-4.18.x.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to