英文:
How to Route message from file to Azure Event Hub Using JAVA Program
问题
//SimpleRouteBuilder
import org.apache.camel.builder.RouteBuilder;
public class SimpleRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("file:d:/InputFolderForCamel").split().tokenize("\n").to("jms:queue:javainuse");
}
}
//MainClass
SimpleRouteBuilder routeBuilder = new SimpleRouteBuilder();
CamelContext ctx = new DefaultCamelContext();
//configure jms component
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://0.0.0.0:61616");
ctx.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
try {
ctx.addRoutes(routeBuilder);
ctx.start();
Thread.sleep(5 * 60 * 1000);
ctx.stop();
} catch (Exception e) {
e.printStackTrace();
}
这段代码在使用ActiveMQ上工作得很好。
我想用Azure Event Hub编写相同的Java程序。文件必须由Camel读取并路由到Azure Event Hub。
英文:
//SimpleRouteBuilder
import org.apache.camel.builder.RouteBuilder;
public class SimpleRouteBuilder extends RouteBuilder{
@Override
public void configure() throws Exception {
from("file:d:/InputFolderForCamel").split().tokenize("\n").to("jms:queue:javainuse");
}
//MainClass
SimpleRouteBuilder routeBuilder = new SimpleRouteBuilder();
CamelContext ctx = new DefaultCamelContext();
//configure jms component
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://0.0.0.0:61616");
ctx.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
try {
ctx.addRoutes(routeBuilder);
ctx.start();
Thread.sleep(5 * 60 * 1000);
ctx.stop();
}
catch (Exception e) {
e.printStackTrace();
}
It is working fine with ActiveMQ.
I would like to write same java program with Azure Event Hub. File must be readed by Camel and routed to Azure Event Hub
答案1
得分: 1
from("file:d:/InputFolderForCamel").split().tokenize("\n").
to("azure-eventhubs://[namespace/eventHubName][?options]");
URI格式:azure-eventhubs://[命名空间/事件中心名称][?选项]
如果您提供了connectionString,则不需要提供namespace和eventHubName,因为这些选项已包含在connectionString中。
例如:`azure-eventhubs://camel/camelHub?sharedAccessName={your-SASpolicyName}&sharedAccessKey={your-SASaccessKey}`
如果要使用原始连接字符串,格式如下:`azure-eventhubs:?connectionString=Endpoint=sb://{your-namespace-name}.servicebus.windows.net/;SharedAccessKeyName={your-SASpolicyName};SharedAccessKey={your-SASaccessKey};EntityPath={event-hub-name}`
您可以从Azure门户获取`sharedAccessName`和`sharedAccessKey`的值 -> 您的事件中心命名空间 -> 'Shared Access Policies' 选项卡。
阅读有关Camel事件中心URI的更多信息[此处](https://camel.apache.org/components/latest/azure-eventhubs-component.html#_uri_options)。
英文:
from("file:d:/InputFolderForCamel").split().tokenize("\n").
to("azure-eventhubs://[namespace/eventHubName][?options]");
URI FORMAT: azure-eventhubs://[namespace/eventHubName][?options]
In case you supply the connectionString, namespace and eventHubName are not required as these options already included in the connectionString.
For example: azure-eventhubs://camel/camelHub?sharedAccessName={your-SASpolicyName}&sharedAccessKey={your-SASaccessKey}
If you want to use raw connection string, it would be azure-eventhubs:?connectionString=Endpoint=sb://{your-namespace-name}.servicebus.windows.net/;SharedAccessKeyName={your-SASpolicyName};SharedAccessKey={your-SASaccessKey};EntityPath={event-hub-name}
You can obtain sharedAccessName
and sharedAccessKey
values from Azure portal -> Your Event Hub namespace -> 'Shared Access Policies' blade.
Read more about event hub URI for Camel here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论