public static <EventT> Write<EventT> write() {
    return new AutoValue_JmsIO_Write.Builder<EventT>().build();
  }
@Test
  public void testWriteMessagesWithErrors() throws Exception {
    int maxPublicationAttempts = 2;
    // Message 1 should fail for Published DoFn handled by the republished DoFn and published to the
    // queue
    // Message 2 should fail both DoFn
    // Message 3 & 4 should pass the publish DoFn
    List<String> data = Arrays.asList("Message 1", "Message 2", "Message 3", "Message 4");

    RetryConfiguration retryConfiguration =
        RetryConfiguration.create(maxPublicationAttempts, null, null);

    WriteJmsResult<String> output =
        pipeline
            .apply(Create.of(data))
            .apply(
                JmsIO.<String>write()
                    .withConnectionFactory(connectionFactory)
                    .withValueMapper(new TextMessageMapperWithErrorAndCounter())
                    .withRetryConfiguration(retryConfiguration)
                    .withQueue(QUEUE)
                    .withUsername(USERNAME)
                    .withPassword(PASSWORD));

    PAssert.that(output.getFailedMessages()).containsInAnyOrder("Message 2");
    pipeline.run();

    Connection connection = connectionFactory.createConnection(USERNAME, PASSWORD);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE));
    int count = 0;
    while (consumer.receive(1000) != null) {
      count++;
    }
    assertEquals(3, count);
  }