Search in sources :

Example 1 with SendLinkHandler

use of com.microsoft.azure.servicebus.amqp.SendLinkHandler in project azure-service-bus-java by Azure.

the class CoreMessageSender method createSendLink.

private void createSendLink() {
    TRACE_LOGGER.info("Creating send link to '{}'", this.sendPath);
    final Connection connection = this.underlyingFactory.getConnection();
    final Session session = connection.session();
    session.setOutgoingWindow(Integer.MAX_VALUE);
    session.open();
    BaseHandler.setHandler(session, new SessionHandler(sendPath));
    final String sendLinkNamePrefix = StringUtil.getShortRandomString();
    final String sendLinkName = !StringUtil.isNullOrEmpty(connection.getRemoteContainer()) ? sendLinkNamePrefix.concat(TrackingUtil.TRACKING_ID_TOKEN_SEPARATOR).concat(connection.getRemoteContainer()) : sendLinkNamePrefix;
    final Sender sender = session.sender(sendLinkName);
    final Target target = new Target();
    target.setAddress(sendPath);
    sender.setTarget(target);
    final Source source = new Source();
    sender.setSource(source);
    SenderSettleMode settleMode = SenderSettleMode.UNSETTLED;
    TRACE_LOGGER.debug("Send link settle mode '{}'", settleMode);
    sender.setSenderSettleMode(settleMode);
    Map<Symbol, Object> linkProperties = new HashMap<>();
    // ServiceBus expects timeout to be of type unsignedint
    linkProperties.put(ClientConstants.LINK_TIMEOUT_PROPERTY, UnsignedInteger.valueOf(Util.adjustServerTimeout(this.underlyingFactory.getOperationTimeout()).toMillis()));
    sender.setProperties(linkProperties);
    SendLinkHandler handler = new SendLinkHandler(CoreMessageSender.this);
    BaseHandler.setHandler(sender, handler);
    sender.open();
    this.sendLink = sender;
}
Also used : SessionHandler(com.microsoft.azure.servicebus.amqp.SessionHandler) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) Connection(org.apache.qpid.proton.engine.Connection) SendLinkHandler(com.microsoft.azure.servicebus.amqp.SendLinkHandler) SenderSettleMode(org.apache.qpid.proton.amqp.transport.SenderSettleMode) Source(org.apache.qpid.proton.amqp.messaging.Source) IAmqpSender(com.microsoft.azure.servicebus.amqp.IAmqpSender) Sender(org.apache.qpid.proton.engine.Sender) Target(org.apache.qpid.proton.amqp.messaging.Target) Session(org.apache.qpid.proton.engine.Session)

Example 2 with SendLinkHandler

use of com.microsoft.azure.servicebus.amqp.SendLinkHandler in project azure-service-bus-java by Azure.

the class RequestResponseLink method createInternalLinks.

private void createInternalLinks() {
    Map<Symbol, Object> commonLinkProperties = new HashMap<>();
    // ServiceBus expects timeout to be of type unsignedint
    commonLinkProperties.put(ClientConstants.LINK_TIMEOUT_PROPERTY, UnsignedInteger.valueOf(Util.adjustServerTimeout(this.underlyingFactory.getOperationTimeout()).toMillis()));
    // Create send link
    final Connection connection = this.underlyingFactory.getConnection();
    Session session = connection.session();
    session.setOutgoingWindow(Integer.MAX_VALUE);
    session.open();
    BaseHandler.setHandler(session, new SessionHandler(this.linkPath));
    String sendLinkNamePrefix = "RequestResponseLink-Sender".concat(TrackingUtil.TRACKING_ID_TOKEN_SEPARATOR).concat(StringUtil.getShortRandomString());
    String sendLinkName = !StringUtil.isNullOrEmpty(connection.getRemoteContainer()) ? sendLinkNamePrefix.concat(TrackingUtil.TRACKING_ID_TOKEN_SEPARATOR).concat(connection.getRemoteContainer()) : sendLinkNamePrefix;
    Sender sender = session.sender(sendLinkName);
    Target sednerTarget = new Target();
    sednerTarget.setAddress(this.linkPath);
    sender.setTarget(sednerTarget);
    Source senderSource = new Source();
    senderSource.setAddress(this.replyTo);
    sender.setSource(senderSource);
    sender.setSenderSettleMode(SenderSettleMode.SETTLED);
    sender.setProperties(commonLinkProperties);
    SendLinkHandler sendLinkHandler = new SendLinkHandler(this.amqpSender);
    BaseHandler.setHandler(sender, sendLinkHandler);
    this.amqpSender.setSendLink(sender);
    TRACE_LOGGER.debug("RequestReponseLink - opening send link to {}", this.linkPath);
    sender.open();
    // Create receive link
    session = connection.session();
    session.setOutgoingWindow(Integer.MAX_VALUE);
    session.open();
    BaseHandler.setHandler(session, new SessionHandler(this.linkPath));
    String receiveLinkNamePrefix = "RequestResponseLink-Receiver".concat(TrackingUtil.TRACKING_ID_TOKEN_SEPARATOR).concat(StringUtil.getShortRandomString());
    String receiveLinkName = !StringUtil.isNullOrEmpty(connection.getRemoteContainer()) ? receiveLinkNamePrefix.concat(TrackingUtil.TRACKING_ID_TOKEN_SEPARATOR).concat(connection.getRemoteContainer()) : receiveLinkNamePrefix;
    Receiver receiver = session.receiver(receiveLinkName);
    Source receiverSource = new Source();
    receiverSource.setAddress(this.linkPath);
    receiver.setSource(receiverSource);
    Target receiverTarget = new Target();
    receiverTarget.setAddress(this.replyTo);
    receiver.setTarget(receiverTarget);
    // Set settle modes
    receiver.setSenderSettleMode(SenderSettleMode.SETTLED);
    receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST);
    receiver.setProperties(commonLinkProperties);
    final ReceiveLinkHandler receiveLinkHandler = new ReceiveLinkHandler(this.amqpReceiver);
    BaseHandler.setHandler(receiver, receiveLinkHandler);
    this.amqpReceiver.setReceiveLink(receiver);
    TRACE_LOGGER.debug("RequestReponseLink - opening receive link to {}", this.linkPath);
    receiver.open();
}
Also used : SessionHandler(com.microsoft.azure.servicebus.amqp.SessionHandler) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) Connection(org.apache.qpid.proton.engine.Connection) Receiver(org.apache.qpid.proton.engine.Receiver) IAmqpReceiver(com.microsoft.azure.servicebus.amqp.IAmqpReceiver) SendLinkHandler(com.microsoft.azure.servicebus.amqp.SendLinkHandler) Source(org.apache.qpid.proton.amqp.messaging.Source) IAmqpSender(com.microsoft.azure.servicebus.amqp.IAmqpSender) Sender(org.apache.qpid.proton.engine.Sender) Target(org.apache.qpid.proton.amqp.messaging.Target) ReceiveLinkHandler(com.microsoft.azure.servicebus.amqp.ReceiveLinkHandler) Session(org.apache.qpid.proton.engine.Session)

Aggregations

IAmqpSender (com.microsoft.azure.servicebus.amqp.IAmqpSender)2 SendLinkHandler (com.microsoft.azure.servicebus.amqp.SendLinkHandler)2 SessionHandler (com.microsoft.azure.servicebus.amqp.SessionHandler)2 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Symbol (org.apache.qpid.proton.amqp.Symbol)2 Source (org.apache.qpid.proton.amqp.messaging.Source)2 Target (org.apache.qpid.proton.amqp.messaging.Target)2 Connection (org.apache.qpid.proton.engine.Connection)2 Sender (org.apache.qpid.proton.engine.Sender)2 Session (org.apache.qpid.proton.engine.Session)2 IAmqpReceiver (com.microsoft.azure.servicebus.amqp.IAmqpReceiver)1 ReceiveLinkHandler (com.microsoft.azure.servicebus.amqp.ReceiveLinkHandler)1 SenderSettleMode (org.apache.qpid.proton.amqp.transport.SenderSettleMode)1 Receiver (org.apache.qpid.proton.engine.Receiver)1