private void SendEventUsingTextFormat()

in publish-events/channel-connection/client-libraries/java/src/main/java/com/google/cloud/eventarc/publishing/example/PublishEventsExample.java [57:77]


  private void SendEventUsingTextFormat(String channelConnectionName, CloudEvent event) {
    byte[] serializedEvent = EventFormatProvider.getInstance()
        .resolveFormat(JsonFormat.CONTENT_TYPE)
        .serialize(event);
    String stringizedEvent = new String(serializedEvent);

    PublishChannelConnectionEventsRequest request = PublishChannelConnectionEventsRequest.newBuilder()
        .setChannelConnection(channelConnectionName)
        .addTextEvents(stringizedEvent)
        .build();
    LOGGER.log(Level.INFO, "Publishing message in Eventarc");
    try {
      // Create a client with credentials provided by the system.
      PublisherClient client = PublisherClient.create();
      PublishChannelConnectionEventsResponse response = client.publishChannelConnectionEvents(request);
      LOGGER.log(Level.INFO, String.format("Message published successfully.\nReceived response: %s",
          response.toString()));
    } catch (Exception ex) {
      LOGGER.log(Level.SEVERE, "An exception occurred while publishing", ex);
    }
  }