4.4. 配置队列和主题名称
JMS 提供了使用 JNDI 查找特定于部署的队列和主题资源的 选项。
若要在 JNDI 中设置队列和主题名称,请以以下格式创建属性:将此配置放在 jndi.properties 文件中,或者设置对应的系统属性。
队列和主题的 JNDI 属性格式
queue.<lookup-name> = <queue-name> topic.<lookup-name> = <topic-name>
queue.<lookup-name> = <queue-name>
topic.<lookup-name> = <topic-name>
例如,以下属性定义了两个部署特定资源的名称 作业和 通知 :
示例:在 jndi.properties 文件中设置队列和主题名称
queue.jobs = app1/work-items topic.notifications = app1/updates
queue.jobs = app1/work-items
topic.notifications = app1/updates
然后,您可以通过其 JNDI 名称查找资源:
Queue queue = (Queue) context.lookup("jobs");
Topic topic = (Topic) context.lookup("notifications");
Queue queue = (Queue) context.lookup("jobs");
Topic topic = (Topic) context.lookup("notifications");