You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "tkaymak (via GitHub)" <gi...@apache.org> on 2026/05/13 21:21:38 UTC

[PR] [mqtt] Add portable MqttIO Read/Write transforms (revives #32385) [beam]

tkaymak opened a new pull request, #38493:
URL: https://github.com/apache/beam/pull/38493

   ## What
   
   Revives the approved diff from [PR #32385](https://github.com/apache/beam/pull/32385) (`Add portable Mqtt source and sink transforms`) and wires the new SchemaTransforms into Python cross-language wrapper generation.
   
   After this lands, Python users can do:
   
   ```python
   from apache_beam.io import ReadFromMqtt, WriteToMqtt
   ```
   
   and reach `MqttIO` over xlang, the same way `ReadFromKafka` / `WriteToKafka` work today.
   
   ## How
   
   Two commits:
   
   1. **`[mqtt] Add SchemaTransform providers for MqttIO Read/Write`**
      - Decorate `MqttIO.ConnectionConfiguration` with `@DefaultSchema(AutoValueSchema.class)` + `@SchemaFieldDescription` so it round-trips through Beam Schemas.
      - New `MqttReadSchemaTransformProvider` (`beam:schematransform:org.apache.beam:mqtt_read:v1`) and `MqttWriteSchemaTransformProvider` (`beam:schematransform:org.apache.beam:mqtt_write:v1`), both `@AutoService`-registered.
      - New `MqttSchemaTransformProviderTest` covering the read-with-timeout-no-data case and a write-then-read round trip via an embedded ActiveMQ broker.
      - Pull `:sdks:java:io:mqtt` into `:sdks:java:io:expansion-service` so the providers are discoverable by `ExpansionService`.
   
   2. **`[mqtt] Wire MqttIO into Python xlang wrapper generation`**
      - Add name overrides in `sdks/standard_expansion_services.yaml` so the generated wrappers use kafka-style naming (`ReadFromMqtt` / `WriteToMqtt`).
      - Regenerate `sdks/standard_external_transforms.yaml` via `:sdks:python:generateExternalTransformsConfig`.
      - Add an I/Os entry to `CHANGES.md` for 2.74.0.
   
   ## Notes vs. PR #32385
   
   - **Generic-typing fix** for the post-#32668 API: `MqttIO.Read<byte[]>` / `MqttIO.Write<byte[]>` instead of the raw types in the original PR.
   - **Naming**: `ReadFromMqtt` / `WriteToMqtt` (kafka-style) instead of the auto-derived `MqttRead` / `MqttWrite`. Per @Abacn's roadmap [comment](https://github.com/apache/beam/pull/32385#issuecomment-4431628903) about onboarding through `standard_expansion_services.yaml`.
   - The original PR's regenerated `standard_external_transforms.yaml` shape changed slightly (`fields` is now a list and Python types have a more compact representation) because `gen_xlang_wrappers.py` evolved since 2024-08. Our regenerated diff follows current master's format.
   - `topic` is now `Optional` in the generated schema because `MqttIO.ConnectionConfiguration#getTopic()` was made `@Nullable` by [PR #32668](https://github.com/apache/beam/pull/32668) (`readWithMetadata`).
   
   ## Scope
   
   **Batch only.** The streaming-mode failure that @twosom flagged on the original PR ([comment](https://github.com/apache/beam/pull/32385#issuecomment-2468417402) — *batch worked, streaming did not*) was never root-caused. That investigation is intentionally out of scope here and will be addressed in a dedicated follow-up PR.
   
   ## Credits
   
   Original work by @ahmedabu98 and @twosom on PR #32385; @damondouglas approved that PR before it went stale and auto-closed on 2025-10-14. This revives that change with the small adjustments above.
   
   ## Verification
   
   ```bash
   GRADLE_USER_HOME=/tmp/.gradle ./gradlew \
       :sdks:java:io:mqtt:test \
       :sdks:java:io:expansion-service:build \
       :validateChanges
   ```
   All pass locally.
   
   R: @Abacn
   
   Closes the gap from #32385 / addresses #21060 (Python MQTT IO).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #38493:
URL: https://github.com/apache/beam/pull/38493#issuecomment-4673316393

   ## Summary of Changes
   
   Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
   
   This pull request revives and enhances the MQTT IO support by introducing portable SchemaTransforms for both reading and writing. By registering these transforms in the expansion service and updating the Python wrapper generation, it allows users to perform batch and streaming MQTT operations seamlessly across language boundaries. The changes also include necessary schema annotations and validation to ensure robust cross-language interoperability.
   
   ### Highlights
   
   * **SchemaTransform Providers**: Implemented MqttReadSchemaTransformProvider and MqttWriteSchemaTransformProvider to enable cross-language support for MQTT IO.
   * **Python SDK Integration**: Wired the new MQTT transforms into the Python SDK via cross-language wrapper generation, enabling ReadFromMqtt and WriteToMqtt.
   * **Schema Annotations**: Decorated MqttIO.ConnectionConfiguration with AutoValueSchema and field descriptions to ensure proper round-tripping through Beam Schemas.
   * **Testing**: Added comprehensive unit tests covering batch and streaming scenarios, including verification with an embedded ActiveMQ broker.
   
   <details>
   <summary><b>New Features</b></summary>
   
   🧠 You can now enable **Memory** (public preview) to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
   </details>
   
   <details>
   <summary><b>Using Gemini Code Assist</b></summary>
   <br>
   
   The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
   
   <b>Invoking Gemini</b>
   
   You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
   
   Feature | Command | Description
   --- | --- | ---
   Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
   Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
   Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
   Help | `/gemini help` | Displays a list of available commands.
   
   <b>Customization</b>
   
   To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
   
   <b>Limitations & Feedback</b>
   
   Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
   </details>
   
   
   [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #38493:
URL: https://github.com/apache/beam/pull/38493#discussion_r3390702978


##########
sdks/java/io/mqtt/src/main/java/org/apache/beam/sdk/io/mqtt/MqttReadSchemaTransformProvider.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.mqtt;
+
+import static org.apache.beam.sdk.io.mqtt.MqttIO.ConnectionConfiguration;
+import static org.apache.beam.sdk.io.mqtt.MqttReadSchemaTransformProvider.ReadConfiguration;
+
+import com.google.auto.service.AutoService;
+import com.google.auto.value.AutoValue;
+import java.io.Serializable;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.schemas.AutoValueSchema;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.annotations.DefaultSchema;
+import org.apache.beam.sdk.schemas.annotations.SchemaFieldDescription;
+import org.apache.beam.sdk.schemas.transforms.SchemaTransform;
+import org.apache.beam.sdk.schemas.transforms.SchemaTransformProvider;
+import org.apache.beam.sdk.schemas.transforms.TypedSchemaTransformProvider;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionRowTuple;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions;
+import org.joda.time.Duration;
+
+@AutoService(SchemaTransformProvider.class)
+public class MqttReadSchemaTransformProvider
+    extends TypedSchemaTransformProvider<ReadConfiguration> {
+  @DefaultSchema(AutoValueSchema.class)
+  @AutoValue
+  public abstract static class ReadConfiguration implements Serializable {
+    public static Builder builder() {
+      return new AutoValue_MqttReadSchemaTransformProvider_ReadConfiguration.Builder();
+    }
+
+    @SchemaFieldDescription("Configuration options to set up the MQTT connection.")
+    public abstract ConnectionConfiguration getConnectionConfiguration();
+
+    @SchemaFieldDescription(
+        "The max number of records to receive. Setting this will result in a bounded PCollection.")
+    @Nullable
+    public abstract Long getMaxNumRecords();
+
+    @SchemaFieldDescription(
+        "The maximum time for this source to read messages. Setting this will result in a bounded PCollection.")
+    @Nullable
+    public abstract Long getMaxReadTimeSeconds();
+
+    @AutoValue.Builder
+    public abstract static class Builder {
+      public abstract Builder setConnectionConfiguration(
+          ConnectionConfiguration connectionConfiguration);
+
+      public abstract Builder setMaxNumRecords(Long maxNumRecords);
+
+      public abstract Builder setMaxReadTimeSeconds(Long maxReadTimeSeconds);
+
+      public abstract ReadConfiguration build();
+    }
+  }
+
+  @Override
+  public String identifier() {
+    return "beam:schematransform:org.apache.beam:mqtt_read:v1";
+  }
+
+  @Override
+  public String description() {
+    return "Reads messages from an MQTT broker and outputs each payload as a single `bytes` "
+        + "field.\n"
+        + "\n"
+        + "By default the read is unbounded (streaming): it keeps consuming messages from the "
+        + "subscribed topic until the pipeline is stopped. Setting `maxNumRecords` and/or "
+        + "`maxReadTimeSeconds` bounds the read, producing a bounded (batch) PCollection.\n"
+        + "\n"
+        + "Note: streaming reads require a runner that supports portable streaming (e.g. Prism, "
+        + "Flink, or Dataflow). The legacy local Python DirectRunner does not execute portable "
+        + "streaming cross-language reads.";
+  }
+
+  @Override
+  protected SchemaTransform from(ReadConfiguration configuration) {
+    return new MqttReadSchemaTransform(configuration);
+  }
+
+  private static class MqttReadSchemaTransform extends SchemaTransform {
+    private final ReadConfiguration config;
+
+    MqttReadSchemaTransform(ReadConfiguration configuration) {
+      this.config = configuration;
+    }
+
+    @Override
+    public PCollectionRowTuple expand(PCollectionRowTuple input) {
+      Preconditions.checkState(
+          input.getAll().isEmpty(),
+          "Expected zero input PCollections for this source, but found: %",
+          input.getAll().keySet());

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The Guava `Preconditions.checkState` error message template uses `%` instead of `%s` as the placeholder. This will prevent the key set from being formatted correctly in the error message. Please use `%s` instead.
   
   ```suggestion
         Preconditions.checkState(
             input.getAll().isEmpty(),
             "Expected zero input PCollections for this source, but found: %s",
             input.getAll().keySet());
   ```



##########
sdks/java/io/mqtt/src/main/java/org/apache/beam/sdk/io/mqtt/MqttWriteSchemaTransformProvider.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.mqtt;
+
+import static org.apache.beam.sdk.io.mqtt.MqttIO.ConnectionConfiguration;
+import static org.apache.beam.sdk.io.mqtt.MqttWriteSchemaTransformProvider.WriteConfiguration;
+
+import com.google.auto.service.AutoService;
+import com.google.auto.value.AutoValue;
+import java.io.Serializable;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.schemas.AutoValueSchema;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.annotations.DefaultSchema;
+import org.apache.beam.sdk.schemas.annotations.SchemaFieldDescription;
+import org.apache.beam.sdk.schemas.transforms.SchemaTransform;
+import org.apache.beam.sdk.schemas.transforms.SchemaTransformProvider;
+import org.apache.beam.sdk.schemas.transforms.TypedSchemaTransformProvider;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionRowTuple;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions;
+
+@AutoService(SchemaTransformProvider.class)
+public class MqttWriteSchemaTransformProvider
+    extends TypedSchemaTransformProvider<WriteConfiguration> {
+  @DefaultSchema(AutoValueSchema.class)
+  @AutoValue
+  public abstract static class WriteConfiguration implements Serializable {
+    public static Builder builder() {
+      return new AutoValue_MqttWriteSchemaTransformProvider_WriteConfiguration.Builder();
+    }
+
+    @SchemaFieldDescription("Configuration options to set up the MQTT connection.")
+    public abstract ConnectionConfiguration getConnectionConfiguration();
+
+    @SchemaFieldDescription(
+        "Whether or not the publish message should be retained by the messaging engine. "
+            + "When a subscriber connects, it gets the latest retained message. "
+            + "Defaults to `False`, which will clear the retained message from the server.")
+    @Nullable
+    public abstract Boolean getRetained();
+
+    @AutoValue.Builder
+    public abstract static class Builder {
+      public abstract Builder setConnectionConfiguration(ConnectionConfiguration foo);

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter name `foo` is generic and non-descriptive. It should be renamed to `connectionConfiguration` to match the property name and improve readability/maintainability.
   
   ```suggestion
         public abstract Builder setConnectionConfiguration(ConnectionConfiguration connectionConfiguration);
   ```



##########
sdks/java/io/mqtt/src/test/java/org/apache/beam/sdk/io/mqtt/MqttSchemaTransformProviderTest.java:
##########
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.mqtt;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ConcurrentSkipListSet;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.PipelineResult;
+import org.apache.beam.sdk.io.common.NetworkTestHelper;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionRowTuple;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.fusesource.hawtbuf.Buffer;
+import org.fusesource.mqtt.client.BlockingConnection;
+import org.fusesource.mqtt.client.MQTT;
+import org.fusesource.mqtt.client.Message;
+import org.fusesource.mqtt.client.QoS;
+import org.fusesource.mqtt.client.Topic;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MqttSchemaTransformProviderTest {
+  private static final Logger LOG = LoggerFactory.getLogger(MqttSchemaTransformProviderTest.class);
+
+  private BrokerService brokerService;
+
+  private int port;
+
+  @Rule public final transient TestPipeline pipeline = TestPipeline.create();
+
+  @Before
+  public void startBroker() throws Exception {
+    port = NetworkTestHelper.getAvailableLocalPort();
+    LOG.info("Starting ActiveMQ brokerService on {}", port);
+    brokerService = new BrokerService();
+    brokerService.setDeleteAllMessagesOnStartup(true);
+    // use memory persistence for the test: it's faster and don't pollute test folder with KahaDB
+    brokerService.setPersistent(false);
+    brokerService.addConnector("mqtt://localhost:" + port);
+    brokerService.start();
+    brokerService.waitUntilStarted();
+  }
+
+  @Test(timeout = 30 * 1000)
+  public void testReceiveWithTimeoutAndNoData() {
+    MqttReadSchemaTransformProvider.ReadConfiguration readConfiguration =
+        MqttReadSchemaTransformProvider.ReadConfiguration.builder()
+            .setConnectionConfiguration(
+                MqttIO.ConnectionConfiguration.create("tcp://localhost:" + port, "READ_TOPIC")
+                    .withClientId("READ_PIPELINE"))
+            .setMaxReadTimeSeconds(2L)
+            .build();
+
+    PCollectionRowTuple.empty(pipeline)
+        .apply(new MqttReadSchemaTransformProvider().from(readConfiguration));
+
+    // should stop before the test timeout
+    pipeline.run().waitUntilFinish();
+  }
+
+  /** Collects the bytes field of every output row into a shared queue (DirectRunner is in-JVM). */
+  private static final ConcurrentLinkedQueue<String> STREAMING_RECEIVED =
+      new ConcurrentLinkedQueue<>();
+
+  private static class CollectBytesFn extends DoFn<Row, Void> {
+    @ProcessElement
+    public void processElement(@Element Row row) {
+      byte[] bytes = row.getBytes("bytes");
+      if (bytes != null) {
+        STREAMING_RECEIVED.add(new String(bytes, StandardCharsets.UTF_8));
+      }
+    }
+  }
+
+  /**
+   * Reads in streaming mode: when neither {@code maxNumRecords} nor {@code maxReadTimeSeconds} is
+   * set the SchemaTransform produces an unbounded PCollection. Verifies that messages published
+   * after the reader subscribes flow through continuously, then cancels the running pipeline.
+   */
+  @Test(timeout = 90 * 1000)
+  public void testReadUnboundedStreaming() throws Exception {
+    STREAMING_RECEIVED.clear();
+    final String topicName = "STREAM_READ_TOPIC";
+
+    // No bound -> unbounded (streaming) read.
+    MqttReadSchemaTransformProvider.ReadConfiguration readConfiguration =
+        MqttReadSchemaTransformProvider.ReadConfiguration.builder()
+            .setConnectionConfiguration(
+                MqttIO.ConnectionConfiguration.create("tcp://localhost:" + port, topicName)
+                    .withClientId("STREAM_READ_PIPELINE"))
+            .build();
+
+    // Use a local pipeline so run() does not block (the read never terminates on its own).
+    PipelineOptions options =
+        PipelineOptionsFactory.fromArgs("--blockOnRun=false").withoutStrictParsing().create();
+    Pipeline p = Pipeline.create(options);
+    PCollectionRowTuple.empty(p)
+        .apply(new MqttReadSchemaTransformProvider().from(readConfiguration))
+        .get("output")
+        .apply(ParDo.of(new CollectBytesFn()));
+
+    // Publish a steady stream of messages until the reader has consumed enough.
+    final boolean[] keepPublishing = {true};
+    MQTT client = new MQTT();
+    client.setHost("tcp://localhost:" + port);
+    final BlockingConnection publishConnection = client.blockingConnection();
+    publishConnection.connect();
+    Thread publisher =
+        new Thread(
+            () -> {
+              int i = 0;
+              try {
+                while (keepPublishing[0]) {
+                  publishConnection.publish(
+                      topicName,
+                      ("stream-" + i).getBytes(StandardCharsets.UTF_8),
+                      QoS.AT_LEAST_ONCE,
+                      false);
+                  i++;
+                  Thread.sleep(200);
+                }
+              } catch (Exception e) {
+                // ignore: connection closed on teardown
+              }
+            });
+
+    PipelineResult result = p.run();
+    publisher.start();
+
+    // Wait until the unbounded read delivers a meaningful number of records.
+    int expected = 10;
+    long deadline = System.currentTimeMillis() + 60 * 1000;
+    while (STREAMING_RECEIVED.size() < expected && System.currentTimeMillis() < deadline) {
+      Thread.sleep(500);
+    }
+
+    keepPublishing[0] = false;
+    publisher.join();
+    publishConnection.disconnect();
+    result.cancel();
+
+    assertTrue(
+        "expected at least " + expected + " streamed records, got " + STREAMING_RECEIVED.size(),
+        STREAMING_RECEIVED.size() >= expected);
+    for (String received : STREAMING_RECEIVED) {
+      assertTrue("unexpected payload: " + received, received.startsWith("stream-"));
+    }
+  }
+
+  @Test
+  public void testWrite() throws Exception {
+    final int numberOfTestMessages = 200;
+    MQTT client = new MQTT();
+    client.setHost("tcp://localhost:" + port);
+    final BlockingConnection connection = client.blockingConnection();
+    connection.connect();
+    connection.subscribe(new Topic[] {new Topic(Buffer.utf8("WRITE_TOPIC"), QoS.EXACTLY_ONCE)});
+
+    final Set<String> messages = new ConcurrentSkipListSet<>();
+
+    Thread subscriber =
+        new Thread(
+            () -> {
+              try {
+                for (int i = 0; i < numberOfTestMessages; i++) {
+                  Message message = connection.receive();
+                  messages.add(new String(message.getPayload(), StandardCharsets.UTF_8));
+                  message.ack();
+                  System.out.println(
+                      "message: " + new String(message.getPayload(), StandardCharsets.UTF_8));

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Using `System.out.println` in unit tests is discouraged as it pollutes the build output. Since a logger (`LOG`) is already defined in this class, please use `LOG.info` or `LOG.debug` with SLF4J parameterized formatting instead.
   
   ```suggestion
                     LOG.info(
                         "message: {}", new String(message.getPayload(), StandardCharsets.UTF_8));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn merged PR #38493:
URL: https://github.com/apache/beam/pull/38493


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "tkaymak (via GitHub)" <gi...@apache.org>.
tkaymak commented on code in PR #38493:
URL: https://github.com/apache/beam/pull/38493#discussion_r3393951859


##########
sdks/java/io/expansion-service/build.gradle:
##########
@@ -89,6 +89,8 @@ dependencies {
   permitUnusedDeclared project(":sdks:java:io:kafka:upgrade") // BEAM-11761
   implementation project(":sdks:java:extensions:kafka-factories")
   permitUnusedDeclared project(":sdks:java:extensions:kafka-factories")
+  implementation project(":sdks:java:io:mqtt")

Review Comment:
   I went with the broader option: a new `:sdks:java:io:messaging-expansion-service` module (rather than mqtt-specific), so JMS/Solace can be added to it later without another module or a rename.
   
   - MqttIO is no longer added to `:sdks:java:io:expansion-service` (that change is reverted).
   - The new module pulls in only `:sdks:java:expansion-service` + `:sdks:java:io:mqtt`
   - `standard_expansion_services.yaml` now has a second entry for the messaging service emitting `ReadFromMqtt`/`WriteToMqtt`; it skips the core SchemaTransforms it bundles transitively, which keep being generated from the io service. Regenerated `standard_external_transforms.yaml` accordingly, and registered the new target in `generateExternalTransformsConfig` and the xlang `servicesToGenerateFrom` list.
   
   Verified the new service end-to-end over xlang (Python → `ReadFromMqtt`, batch + streaming on Prism) against a local broker.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "tkaymak (via GitHub)" <gi...@apache.org>.
tkaymak commented on PR #38493:
URL: https://github.com/apache/beam/pull/38493#issuecomment-4691466977

   Thanks for the review @Abacn! Both inline comments addressed in `9b0956f6099` (workaround line removed in both expansion-service modules; CHANGES.md entry deferred).
   
   I'll follow up with a separate PR that sets up `beam_PostCommit_Python_Xlang_Messaging_Direct` modeled on the Xlang IO/GCP Direct workflows — Direct runner with an MQTT broker via testcontainers, plus a Python cross-language IT (`WriteToMqtt` → bounded `ReadFromMqtt`), and the CHANGES.md announcement once that's green. Agreed that Dataflow is out of scope for now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "tkaymak (via GitHub)" <gi...@apache.org>.
tkaymak commented on code in PR #38493:
URL: https://github.com/apache/beam/pull/38493#discussion_r3393951859


##########
sdks/java/io/expansion-service/build.gradle:
##########
@@ -89,6 +89,8 @@ dependencies {
   permitUnusedDeclared project(":sdks:java:io:kafka:upgrade") // BEAM-11761
   implementation project(":sdks:java:extensions:kafka-factories")
   permitUnusedDeclared project(":sdks:java:extensions:kafka-factories")
+  implementation project(":sdks:java:io:mqtt")

Review Comment:
   Good call — done in `2204a9d79d0`. I went with the broader option: a new `:sdks:java:io:messaging-expansion-service` module (rather than mqtt-specific), so JMS/Solace can be added to it later without another module or a rename.
   
   - MqttIO is no longer added to `:sdks:java:io:expansion-service` (that change is reverted).
   - The new module pulls in only `:sdks:java:expansion-service` + `:sdks:java:io:mqtt` (shadowJar is ~60 MB vs the io service's ~466 MB).
   - `standard_expansion_services.yaml` now has a second entry for the messaging service emitting `ReadFromMqtt`/`WriteToMqtt`; it skips the core SchemaTransforms it bundles transitively (`generate_sequence`, `tfrecord_*`), which keep being generated from the io service. Regenerated `standard_external_transforms.yaml` accordingly, and registered the new target in `generateExternalTransformsConfig` and the xlang `servicesToGenerateFrom` list.
   
   Verified the new service end-to-end over xlang (Python → `ReadFromMqtt`, batch + streaming on Prism) against a local broker.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on code in PR #38493:
URL: https://github.com/apache/beam/pull/38493#discussion_r3393116051


##########
sdks/java/io/expansion-service/build.gradle:
##########
@@ -89,6 +89,8 @@ dependencies {
   permitUnusedDeclared project(":sdks:java:io:kafka:upgrade") // BEAM-11761
   implementation project(":sdks:java:extensions:kafka-factories")
   permitUnusedDeclared project(":sdks:java:extensions:kafka-factories")
+  implementation project(":sdks:java:io:mqtt")

Review Comment:
   Also with @chamikaramj we recommend put mqttio into a new expansion service module,
   
   I'm considering either in io/mqtt/expansion-service or a bit generic io/messagin-expansion-service that serving messaging protocols (mqtt, and possibly jms, solace in the future)



##########
sdks/java/io/expansion-service/build.gradle:
##########
@@ -89,6 +89,8 @@ dependencies {
   permitUnusedDeclared project(":sdks:java:io:kafka:upgrade") // BEAM-11761
   implementation project(":sdks:java:extensions:kafka-factories")
   permitUnusedDeclared project(":sdks:java:extensions:kafka-factories")
+  implementation project(":sdks:java:io:mqtt")

Review Comment:
   Also discussed with @chamikaramj we recommend put mqttio into a new expansion service module,
   
   I'm considering either in io/mqtt/expansion-service or a bit generic io/messagin-expansion-service that serving messaging protocols (mqtt, and possibly jms, solace in the future)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "tkaymak (via GitHub)" <gi...@apache.org>.
tkaymak commented on code in PR #38493:
URL: https://github.com/apache/beam/pull/38493#discussion_r3393951859


##########
sdks/java/io/expansion-service/build.gradle:
##########
@@ -89,6 +89,8 @@ dependencies {
   permitUnusedDeclared project(":sdks:java:io:kafka:upgrade") // BEAM-11761
   implementation project(":sdks:java:extensions:kafka-factories")
   permitUnusedDeclared project(":sdks:java:extensions:kafka-factories")
+  implementation project(":sdks:java:io:mqtt")

Review Comment:
   Thanks for the pointers @Abacn! I went with the broader option: a new `:sdks:java:io:messaging-expansion-service` module (rather than mqtt-specific), so JMS/Solace can be added to it later without another module or a rename.
   
   - MqttIO is no longer added to `:sdks:java:io:expansion-service` (that change is reverted).
   - The new module pulls in only `:sdks:java:expansion-service` + `:sdks:java:io:mqtt`
   - `standard_expansion_services.yaml` now has a second entry for the messaging service emitting `ReadFromMqtt`/`WriteToMqtt`; it skips the core SchemaTransforms it bundles transitively, which keep being generated from the io service. Regenerated `standard_external_transforms.yaml` accordingly, and registered the new target in `generateExternalTransformsConfig` and the xlang `servicesToGenerateFrom` list.
   
   Verified the new service end-to-end over xlang (Python → `ReadFromMqtt`, batch + streaming on Prism) against a local broker.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on code in PR #38493:
URL: https://github.com/apache/beam/pull/38493#discussion_r3396667457


##########
CHANGES.md:
##########
@@ -66,9 +66,11 @@
 ## I/Os
 
 * Support for X source added (Java/Python) ([#X](https://github.com/apache/beam/issues/X)).
+* MqttIO: portable `ReadFromMqtt` / `WriteToMqtt` transforms now available in Python via cross-language (`apache_beam.io`), for both batch and streaming ([#32385](https://github.com/apache/beam/issues/32385)).

Review Comment:
   As usual let's defer the announcement until tests have setup and are green



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #38493:
URL: https://github.com/apache/beam/pull/38493#issuecomment-4673401662

   That's great to hear, @tkaymak! Thank you for confirming those fixes and for keeping the commit history clean. The changes look solid, and the addition of the portable MQTT IO transforms will be a valuable asset for the Beam community. Since you've addressed the feedback, this looks ready to move forward.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on code in PR #38493:
URL: https://github.com/apache/beam/pull/38493#discussion_r3396629784


##########
sdks/java/io/messaging-expansion-service/build.gradle:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+apply plugin: 'org.apache.beam.module'
+apply plugin: 'application'
+mainClassName = "org.apache.beam.sdk.expansion.service.ExpansionService"
+
+applyJavaNature(
+  automaticModuleName: 'org.apache.beam.sdk.io.messaging.expansion.service',
+  exportJavadoc: false,
+  validateShadowJar: false,
+  shadowClosure: {},
+)
+
+shadowJar {
+  manifest {
+    attributes(["Multi-Release": true])
+  }
+  mergeServiceFiles()
+  outputs.upToDateWhen { false }

Review Comment:
   > outputs.upToDateWhen { false }
   
   This line was a workaround for corrupted gradle cache. It should have been removed from io/expansion-service.build.gradle as well and we don't need it here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "tkaymak (via GitHub)" <gi...@apache.org>.
tkaymak commented on PR #38493:
URL: https://github.com/apache/beam/pull/38493#issuecomment-4692207219

   Status of the failing checks (none related to this PR):
   
   - **beam_PreCommit_Java_Amazon-Web-Services2_IO_Direct** — `SqsIOWriteBatchesTest.testWriteBatchesWithTimeout`, the recurring Mockito flake (master is green on recent scheduled runs). Filed #38946 to track it; retriggered the check above.
   - **beam_PreCommit_Python_ML 3.13** (both runner types) — the Milvus RAG integration suites currently fail on **every** `master` run (last 4 completed runs red, mostly 10-minute container timeouts), so a retrigger here won't help. Filed #38945 with the evidence. This PR touches no ML code.
   
   The xlang check that validates this PR (`beam_PreCommit_Xlang_Generated_Transforms`) is green.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "tkaymak (via GitHub)" <gi...@apache.org>.
tkaymak commented on PR #38493:
URL: https://github.com/apache/beam/pull/38493#issuecomment-4692206738

   Run Java_Amazon-Web-Services2_IO_Direct PreCommit


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "tkaymak (via GitHub)" <gi...@apache.org>.
tkaymak commented on PR #38493:
URL: https://github.com/apache/beam/pull/38493#issuecomment-4673395729

   Thanks @gemini-code-assist — all three are fair, applied in `c7d09d04a96`:
   
   1. **`%` → `%s`** in the `checkState` message in `MqttReadSchemaTransformProvider` — genuine bug, the key set wouldn't have rendered.
   2. **`foo` → `connectionConfiguration`** on the write builder setter — agreed, leftover from the revived #32385 diff.
   3. **`System.out.println` → `LOG.info`** with parameterized formatting in the test.
   
   (Folded into the existing two commits to keep the history tidy rather than adding a fixup commit.)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #38493:
URL: https://github.com/apache/beam/pull/38493#issuecomment-4675160089

   Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment `assign set of reviewers`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "tkaymak (via GitHub)" <gi...@apache.org>.
tkaymak commented on code in PR #38493:
URL: https://github.com/apache/beam/pull/38493#discussion_r3403495249


##########
sdks/java/io/messaging-expansion-service/build.gradle:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+apply plugin: 'org.apache.beam.module'
+apply plugin: 'application'
+mainClassName = "org.apache.beam.sdk.expansion.service.ExpansionService"
+
+applyJavaNature(
+  automaticModuleName: 'org.apache.beam.sdk.io.messaging.expansion.service',
+  exportJavadoc: false,
+  validateShadowJar: false,
+  shadowClosure: {},
+)
+
+shadowJar {
+  manifest {
+    attributes(["Multi-Release": true])
+  }
+  mergeServiceFiles()
+  outputs.upToDateWhen { false }

Review Comment:
   Removed in `9b0956f6099` — from this module and from `io/expansion-service/build.gradle` as well (separate small commit, since that module is otherwise untouched by this PR).



##########
CHANGES.md:
##########
@@ -66,9 +66,11 @@
 ## I/Os
 
 * Support for X source added (Java/Python) ([#X](https://github.com/apache/beam/issues/X)).
+* MqttIO: portable `ReadFromMqtt` / `WriteToMqtt` transforms now available in Python via cross-language (`apache_beam.io`), for both batch and streaming ([#32385](https://github.com/apache/beam/issues/32385)).

Review Comment:
   Makes sense — removed the CHANGES.md entry in `9b0956f6099`. I'll re-add the announcement in the follow-up PR that sets up the Xlang Messaging PostCommit, once it's green.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [mqtt] Add portable MqttIO Read/Write transforms for batch and streaming (revives #32385) [beam]

Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on PR #38493:
URL: https://github.com/apache/beam/pull/38493#issuecomment-4699470393

   Thank you!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org