【问题标题】:Camel set header before from骆驼在从之前设置标题
【发布时间】:2022-10-08 04:46:39
【问题描述】:

我有一个端点,想在发送到 API 之前设置一个标头。

Stream.of("a", "b").forEach(id) -> {
    from("azure-storage-blob://devstoreaccount1/hotfolder?serviceClient=#blobServiceClient&operation=listBlobs")
    .routeId(id)
    .autoStartup(false)
    .tracing()
     // this should happen before the the azure call
    .setHeader("MyHeader", () -> id)
    .process(exchange -> {
        ArrayList<BlobItem> items = exchange.getIn().getBody(ArrayList.class);
        for (BlobItem blobItem : items) {
            System.out.println(blobItem.getName());
        }
    });
}

稍后当上下文启动时,我在其他地方开始路由

final Route route = camelContext.getRoute("a");
ServiceHelper.startService(route.getConsumer());

现在它尝试引入一条新路由来触发旧路由并设置标题。

from("direct:intermediate")
  .noAutoStartup()
  .routeId("intermediate")
  .to("direct:hf");

from("direct:hf")
  .setHeader("MyHeader", () -> id)
  .to("azure-storage-blob://devstoreaccount1/hotfolder?serviceClient=#blobServiceClient&operation=listBlobs")
  .process(exchange -> {
      ArrayList<BlobItem> items = exchange.getIn().getBody(ArrayList.class);
      for (BlobItem blobItem : items) {
          System.out.println(blobItem.getName());
      }
  });

final Route route = camelContext.getRoute("intermediate");
ServiceHelper.startService(route.getConsumer());

但是路线什么也没做。 有没有办法用骆驼做一些事情?

【问题讨论】:

  • 标题的目的是什么?在这两个示例中打印文件名是否适合您?
  • Header 用于设置一些 CamelAzureStorageBlob* 标头。即带有前缀 () 的 CamelAzureStorageBlobListBlobOptions。如果我将 url 中的前缀设置为请求参数,则它不会传递到端点。我检查了一下,两者实际上都不起作用。
  • 这应该可以在发送到 azure-data-storage-blob 组件之前设置您的标头。根据文档和代码,它将获取附加到骆驼消息的 CamelAzureStorageBlobListBlobOptions 标头。
  • 似乎问题在于启动路线本身。如果我直接开始:hf 使用计时器代替它可以工作。但不幸的是,我需要使用 noAutoStartup。
  • 我不明白为什么没有从 requestParameter 中提取前缀(例如“&prefix=test”。在 BlobConfigurationOptionsProxy 中,我可以看到它仅从 Exchange 标头中读取)。这将解决所有解决方法。

标签: java apache-camel spring-camel


【解决方案1】:

仅仅因为还没有消息,所以无法在 from 之前设置标头。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2013-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多