use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionProducerCreditsMessage in project activemq-artemis by apache.
the class CoreSessionCallback method sendProducerCreditsMessage.
@Override
public void sendProducerCreditsMessage(int credits, SimpleString address) {
Packet packet = new SessionProducerCreditsMessage(credits, address);
channel.send(packet);
}
use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionProducerCreditsMessage in project activemq-artemis by apache.
the class ReattachTest method testOverflowCredits.
/*
* Test failure on connection, but server is still up so should immediately reconnect
*/
@Test
public void testOverflowCredits() throws Exception {
final long retryInterval = 500;
final double retryMultiplier = 1d;
final int reconnectAttempts = 1;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024).setProducerWindowSize(1000);
final AtomicInteger count = new AtomicInteger(0);
Interceptor intercept = new Interceptor() {
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
System.out.println("Intercept..." + packet.getClass().getName());
if (packet instanceof SessionProducerCreditsMessage) {
SessionProducerCreditsMessage credit = (SessionProducerCreditsMessage) packet;
System.out.println("Credits: " + credit.getCredits());
if (count.incrementAndGet() == 2) {
System.out.println("Failing");
connection.fail(new ActiveMQException(ActiveMQExceptionType.UNSUPPORTED_PACKET, "bye"));
return false;
}
}
return true;
}
};
locator.addIncomingInterceptor(intercept);
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
session.createQueue(ReattachTest.ADDRESS, ReattachTest.ADDRESS, null, false);
ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
final int numMessages = 10;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
message.putIntProperty(new SimpleString("count"), i);
message.getBodyBuffer().writeBytes(new byte[5000]);
producer.send(message);
}
session.close();
sf.close();
}
use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionProducerCreditsMessage in project activemq-artemis by apache.
the class FailoverOnFlowControlTest method testOverflowSend.
@Test
public void testOverflowSend() throws Exception {
ServerLocator locator = getServerLocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setReconnectAttempts(300).setProducerWindowSize(1000).setRetryInterval(100);
final ArrayList<ClientSession> sessionList = new ArrayList<>();
Interceptor interceptorClient = new Interceptor() {
AtomicInteger count = new AtomicInteger(0);
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
log.debug("Intercept..." + packet.getClass().getName());
if (packet instanceof SessionProducerCreditsMessage) {
SessionProducerCreditsMessage credit = (SessionProducerCreditsMessage) packet;
log.debug("Credits: " + credit.getCredits());
if (count.incrementAndGet() == 2) {
log.debug("### crashing server");
try {
InVMConnection.setFlushEnabled(false);
crash(false, sessionList.get(0));
} catch (Exception e) {
e.printStackTrace();
} finally {
InVMConnection.setFlushEnabled(true);
}
return false;
}
}
return true;
}
};
locator.addIncomingInterceptor(interceptorClient);
ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
ClientSession session = sf.createSession(true, true);
sessionList.add(session);
session.createQueue(ADDRESS, ADDRESS, null, true);
ClientProducer producer = session.createProducer(ADDRESS);
final int numMessages = 10;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeBytes(new byte[5000]);
message.putIntProperty("counter", i);
producer.send(message);
}
session.close();
}
Aggregations